Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert query

Author  Topic 

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-09-01 : 21:24:31
I would really appreciate some feedback on this!!

insert into table1 (col1, col2, col3, col4)
select @Variable1, col2, col3, col4
from table2
where col2=@Variable2

Is the above query correct and how can I assign each of the variables the 2 values. Depending on the situation for ex. if var1=45 then var2=12435 (gets specific value)

Thanks!!

SA

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-09-02 : 02:44:27
Depending on the situation for ex. if var1=45 then var2=12435 (gets specific value)
can u explain more clearly.. is var2,var1 are columns in table2?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-02 : 03:03:28

something like

select @Variable2=case when @Variable1=45 then 12435 else 100 end

insert into table1 (col1, col2, col3, col4)
select @Variable1, col2, col3, col4
from table2
where col2=@Variable2

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-09-02 : 12:34:15
Thanks. It works like a charm.

SA
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-03 : 02:28:15
quote:
Originally posted by agarwasa2008

Thanks. It works like a charm.

SA


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -