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 |
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2013-05-07 : 10:18:21
|
In my below query, i am getting data twice..declare @plan_id intdeclare @frame_id varchar(max)set @plan_id = 17set @frame_id = '1234580243,1234618815' Select * into #Temp1 From dbo.Split(@frame_id,',') Select @plan_id 'Plan',B.item 'FrameID', 1 'User' From #temp1 A Cross Apply(Select * From dbo.Split(@frame_id,','))B Drop table #temp1 RESULT Plan FrameIDUser17 1234580243117 1234580243117 1234618815117 12346188151kindly suggestTHANKSSHANMUGARAJnshanmugaraj@gmail.com |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-07 : 10:24:01
|
I am not clear on why you would need to use the split function twice. Simply remove the cross apply and the subquery that follows it. Wouldn't that give you what you are looking for?If you do need the cross apply (for some reason that is not clear to me) you need to correlate the inner select in the cross apply with something fromthe outer query. Does your split function give you a serial number also? If so, you would do something like Cross Apply(Select * From dbo.Split(@frame_id,',') WHERE itemNumber = a.itemNumber )B |
|
|
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2013-05-07 : 10:27:36
|
Can you let me know the best query to write using subquery instead of cross join...THANKSSHANMUGARAJnshanmugaraj@gmail.com |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-07 : 10:29:48
|
What is the output you are trying to get? |
|
|
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2013-05-07 : 10:31:53
|
i have fixed as below Select item into #Temp1 From dbo.Split(@frame_id,',') Select @plan_id 'Plan',A.item 'FrameID', 1 'User' From #temp1 A Drop table #temp1THANKSSHANMUGARAJnshanmugaraj@gmail.com |
|
|
|
|
|
|
|