SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sp data dupicated
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shanmugaraj
Posting Yak Master

212 Posts

Posted - 05/07/2013 :  10:18:21  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

3326 Posts

Posted - 05/07/2013 :  10:24:01  Show Profile  Reply with Quote
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

212 Posts

Posted - 05/07/2013 :  10:27:36  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

3326 Posts

Posted - 05/07/2013 :  10:29:48  Show Profile  Reply with Quote
What is the output you are trying to get?
Go to Top of Page

shanmugaraj
Posting Yak Master

212 Posts

Posted - 05/07/2013 :  10:31:53  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.36 seconds. Powered By: Snitz Forums 2000