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 |
|
java148
Yak Posting Veteran
63 Posts |
Posted - 2011-11-24 : 08:27:10
|
how to declare an array type in T-SQL? I don't want to use join. Code is like this:declare @idArray Array;select @idArray = id from mytbl;select * from anotherTbl where id in (@idArray) Thanks. Happy holiday ! |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-11-24 : 08:41:33
|
| There is no array data type in SQL. In most cases table (a physical table, view, or any virtual table) can be used to achieve the functionality of an array. But then, you will need to use joins to use the data. Do you have a specific concern, perhaps performance-related, that makes you want to stay away from joins? |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-11-24 : 09:00:29
|
Just to add to my previous post, you CAN do the following:DECLARE @idArray TABLE (id INT);INSERT INTO @idArray Select id from myTbl;select * from anotherTbl where id in (select id from @idArray); |
 |
|
|
java148
Yak Posting Veteran
63 Posts |
Posted - 2011-11-24 : 21:42:37
|
| thanks, works . |
 |
|
|
|
|
|