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.
| Author |
Topic |
|
tamancha.1
Starting Member
37 Posts |
Posted - 2010-04-27 : 14:18:02
|
| (select distinct(user_id)from #work_4_unwhere mycount=1)intersect(select distinct(user_id)from #work_4_unwhere mycount=2)into #testError: Msg 156, Level 15, State 1, Line 8Incorrect syntax near the keyword 'into'.But this works, why?(select distinct(user_id)from #work_4_unwhere mycount=1)intersect(select distinct(user_id)from #work_4_unwhere mycount=2)I want to store the results into table. |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2010-04-27 : 14:26:28
|
| [code]select * into #test from (select distinct(user_id)from #work_4_unwhere mycount=1intersectselect distinct(user_id)from #work_4_unwhere mycount=2)t[/code] |
 |
|
|
tamancha.1
Starting Member
37 Posts |
Posted - 2010-04-27 : 14:37:09
|
| Thanks, Why do we have a t here in the end.Why it does not work without a t,May be sQL statement cant end with ) |
 |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2010-04-27 : 14:43:55
|
| You have to give it an alias. you can use AS TABLE1 as long as there's an alias. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-28 : 05:54:37
|
quote: Originally posted by tamancha.1 Thanks, Why do we have a t here in the end.Why it does not work without a t,May be sQL statement cant end with )
t is name given for table you created on the fly in query------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|