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
 sp data dupicated

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 int
declare @frame_id varchar(max)
set @plan_id = 17
set @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 FrameID
User
17 1234580243
1
17 1234580243
1
17 1234618815
1
17 1234618815
1

kindly suggest

THANKS
SHANMUGARAJ
nshanmugaraj@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
Go to Top of Page

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...

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

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?
Go to Top of Page

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 #temp1

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page
   

- Advertisement -