Hi @nononame2021
Maybe you just need a DELETE statement, like this:
DELETE FROM table_A
WHERE LEN(DATETIME_Field) > 0
Best regards,
LiHong
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I would like to select datetime filed from table A, if it has value or not null & not empty, then delete data from table A.
can i write this logic in sql execution task directly? how to declear variable @hasvalue=select .....?
if variable has value then .... else .....
any sample for me to reference.
my sql in execution sql task (direct input) as below:
declare @apl varchar(100);
set @apl =(select top 1 mytable_timestamp from [dbo].[table_2])
if isnull(@apl ,'')<>'' then
delete from [dbo].[table_1] ;
insert into [table_1] select * from [table_2];
else
delete from [dbo].[table_2] ;
i got error as below:
[Execute SQL Task] Error: Executing the query "declare @apl varchar(100);
set @apl =(select top ..." failed with the following error: "Incorrect syntax near the keyword 'else'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Hi @nononame2021
Maybe you just need a DELETE statement, like this:
DELETE FROM table_A
WHERE LEN(DATETIME_Field) > 0
Best regards,
LiHong
declare @apl varchar(100);
set @apl =(select top 1 mytable_timestamp from [dbo].[table_2])
if isnull(@apl ,'')<>'' then
delete from [dbo].[table_1] ;
insert into [table_1] select from [table_2];
else
delete from [dbo].[table_2]
Syntactically you are missing a BEGIN:END here. And you are having a THEN too many
declare @date varchar(100);
set @date=(select top 1 mytable_timestamp from [dbo].[table_2])
if isnull(@date,'')<>''
BEGIN
delete from [dbo].[table_1] ;
insert into [table_1] select from [table_2];
END
else
delete from [dbo].[table_2]