briangriffin
Programmer
SQL Server 2005
Trying to do a union with variables:
declare @v_datecutoff datetime
declare @v_table
(value1)
insert into @v_table
select value from sometable where datevalue < @v_datecutoff
UNION ALL
declare @v_datecutoff2 datetime
declare @v_table2
(value1)
insert into @v_table2
select value from sometable2 where datevalue < @v_datecutoff2
-----------------
Each query runs individually, but when running the entire query I get "Incorrect syntax near the keyword declare", and it's pointing to the first word of the second query.
What's going on, and what can I do about it?
Thanks in advance.
Trying to do a union with variables:
declare @v_datecutoff datetime
declare @v_table
(value1)
insert into @v_table
select value from sometable where datevalue < @v_datecutoff
UNION ALL
declare @v_datecutoff2 datetime
declare @v_table2
(value1)
insert into @v_table2
select value from sometable2 where datevalue < @v_datecutoff2
-----------------
Each query runs individually, but when running the entire query I get "Incorrect syntax near the keyword declare", and it's pointing to the first word of the second query.
What's going on, and what can I do about it?
Thanks in advance.