Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

comma seperated parameter Expand / Collapse
Author
Message
Posted Thursday, February 19, 2009 7:32 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Posted Thursday, February 19, 2009 9:21 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:38 PM
Points: 13,999, Visits: 28,378
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 Query Performance Tuning
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
Posted Thursday, February 19, 2009 9:42 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Posted Thursday, February 19, 2009 10:36 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:38 PM
Points: 13,999, Visits: 28,378
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 Query Performance Tuning
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
Posted Friday, February 20, 2009 9:51 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:26 PM
Points: 35,547, Visits: 32,132
Thanks for the kudo, Grant. :)

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

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

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #661961
Posted Saturday, February 21, 2009 4:36 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:38 PM
Points: 13,999, Visits: 28,378
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 Query Performance Tuning
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
Posted Saturday, February 21, 2009 5:30 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: 2 days ago @ 8:50 PM
Points: 20,584, Visits: 9,623
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
Posted Saturday, February 21, 2009 8:18 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:26 PM
Points: 35,547, Visits: 32,132
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 "Row-By-Agonizing-Row".

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

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #662042
Posted Saturday, February 21, 2009 9:08 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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 »

Add to briefcase

Permissions Expand / Collapse