Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Development
»
comma seperated parameter
comma seperated parameter
Rate Topic
Display Mode
Topic Options
Author
Message
Naveen Kumar-807681
Naveen Kumar-807681
Posted Thursday, February 19, 2009 7:32 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Monday, May 14, 2012 2:54 AM
Points: 162,
Visits: 78
hi everybody,
i have 3 tables
1. customer_master(customerid, customername)
2. language_master(languageid, languagename)
3. customer_language(customerid, languageid)
i will get a parameter like 'english, kannada, punjabi' to my stored procedure or query. how simple can I get all the customers who speak all the 3 languages.
Who is wise? He that learns from everyone. Who is powerful? He that governs his passions. Who is rich? He that is content. Who is that? Nobody.:)
Post #660299
Grant Fritchey
Grant Fritchey
Posted Thursday, February 19, 2009 9:21 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
There are a bunch of functions available in the Scripts area of the site. You do a search to track them down. Here's the one at the top of the list:
http://www.sqlservercentral.com/scripts/Miscellaneous/31913/
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #660495
Naveen Kumar-807681
Naveen Kumar-807681
Posted Thursday, February 19, 2009 9:42 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Monday, May 14, 2012 2:54 AM
Points: 162,
Visits: 78
Thanks for ur reply. is there any other better way to do this?
Who is wise? He that learns from everyone. Who is powerful? He that governs his passions. Who is rich? He that is content. Who is that? Nobody.:)
Post #660535
Grant Fritchey
Grant Fritchey
Posted Thursday, February 19, 2009 10:36 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
I know of four ways to do this, a function, a tally table, ad hoc queries or changing the data to XML. You have a function.
This article
is by Jeff Moden. He's the man where this is concerned. You can simply build a query so that you can insert your comma-delimited list into an IN clause, but that's going to cause recompiles and possibly bad performance. Converting to XML will work, but it's much more memory intensive and slower. I'd stick with the tally table (1st choice) or the function (2nd choice).
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #660582
Jeff Moden
Jeff Moden
Posted Friday, February 20, 2009 9:51 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 4:51 PM
Points: 32,923,
Visits: 26,811
Thanks for the kudo, Grant. :)
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #661961
Grant Fritchey
Grant Fritchey
Posted Saturday, February 21, 2009 4:36 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
Credit where it's due.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #662013
Ninja's_RGR'us
Ninja's_RGR'us
Posted Saturday, February 21, 2009 5:30 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 3:18 AM
Points: 21,359,
Visits: 9,541
Credit is due and all good, but that still does not answer the question....
SELECT m.customerid, m.customername
FROM dbo.customer_master m
inner join dbo.customer_language cl on m.customerid = cl.customerid
inner join dbo.language_master lm on cl.languageid = lm.languageid
where lm.languagename IN (Select languageName from dbo.JeffsFunction(@Languages)) -- Fetch the languages here with Jeff's code
--this is the not so obvious part that answer the question you are asking
GROUP BY m.customerid, m.customername
HAVING COUNT(*) = (SELECT COUNT(*) FROM dbo.JeffsFunction)
You need to know how many languages are in the parameter string (can be in a separate parameter to avoid calling the split function twice), then you need to count how many languages are matching per customer and make sure that those 2 numbers are equal... hence that customer speaks all required languages.
Post #662016
Jeff Moden
Jeff Moden
Posted Saturday, February 21, 2009 8:18 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 4:51 PM
Points: 32,923,
Visits: 26,811
Ninja's_RGR'us (2/21/2009)
Credit is due and all good, but that still does not answer the question....
True enough... we were waiting on some test data so we could show some tested code.
Naveen
, take a look at the article in my signature below to get better answers quicker.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #662042
Naveen Kumar-807681
Naveen Kumar-807681
Posted Saturday, February 21, 2009 9:08 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Monday, May 14, 2012 2:54 AM
Points: 162,
Visits: 78
Hi
Thanks for all the replies and suggestions. here is the query to get the required reuslt
SELECT c.customer
FROM #customer_master c
INNER JOIN
(
SELECT cl.customerid,COUNT(DISTINCT l.languagename) AS langcnt
FROM #customer_language cl
INNER JOIN #language_master l
ON l.languageid=cl.languageid
INNER JOIN (SELECT ltrim(f.Val) as val FROM dbo.split(@param,',')f)t
ON t.Val=l.languagename
GROUP BY cl.customerid
)tmp
ON tmp.customerid=c.customerid
WHERE langcnt=(SELECT COUNT(DISTINCT f1.Val) FROM dbo.split(@param,',')f1)
parametere will be like
@param = 'hindi, telugu'
Who is wise? He that learns from everyone. Who is powerful? He that governs his passions. Who is rich? He that is content. Who is that? Nobody.:)
Post #662048
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.