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
 how to filter this?

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2012-10-16 : 10:25:50
Hi there,

I have a question about filtering in select statement. Table1 has a col Code, now I need to run Select * from Table1 and if Code='ABC' then I need select result and also need to write the result into Table2. How can I do this? Thanks in advance.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-10-16 : 10:40:48
insert into table2(column list)
select column list from Table1 and Code='ABC'

Madhivanan

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

allan8964
Posting Yak Master

249 Posts

Posted - 2012-10-16 : 10:55:42
Thanks madhivanan. But I am afraid this is not what I am looking for. I need 1) select results 2) only if Code='ABC' then write the result into table2. Your code only works for 2). The codes will be in an sp. and the sp will be called in different scenarios. Only in the scenario that Code='ABC' it writes to table2. I am afraid there is no solution for this scenario, wish I am wrong.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-11-02 : 04:18:55
Is this what you want?

select column list from Table1

insert into table2(column list)
select column list from Table1 and Code='ABC'



Madhivanan

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

- Advertisement -