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
 New to stored procs

Author  Topic 

Astaroth
Starting Member

9 Posts

Posted - 2007-11-13 : 17:49:56
I am trying to improve my SQL and reduce the number of connections my website is making to the server.

Currently I have a stored procedure that gets all the games (and their details) for a single user which works fine which uses a WHERE userid = @userid which is an Int value.

I now need to create a new procedure which brings back the to all their "friends" (again by their userid). How is it best to do this? I originally tried to do a WHERE userID IN (@userid) but was unable to work out what variable type to use for @userid.

Is it best to do a single query in this way or is there a way to use the existing SP, loop through the collection of userids and join the result together into a single set to return? If an IN is the best route, what is the correct datatype for the variable?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-13 : 17:54:47
Look for all posts by Mike123 here at SQLTeam. You can learn a lot from the suggestions made.
http://www.sqlteam.com/forums/search.asp?mode=DoIt&MEMBER_ID=3906



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Astaroth
Starting Member

9 Posts

Posted - 2007-11-14 : 04:08:59
Peso

Thanks for the suggestion but Mike has made a lot of posts and in the first 20 or so I have looked at there was nothing of relevance that I could see. Could you possibly narrow it down? Unfortunately searching for "in" inevitably doesnt work well.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-14 : 04:16:13
Then you should start by posting your table layout with proper and accurate sample data.
Then you should write what the data represents and then write how the expected output should look like and why.

Welcome back.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-14 : 04:18:48
Or see this blog entry
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Astaroth
Starting Member

9 Posts

Posted - 2007-11-15 : 04:13:27
I wasnt really sure of the relevancy of the over all structure of the db given there are 8 large tables with several interdependencies involved in the query but the question of "what param type to use for an 'in' for an int column type" isnt effected by the rest.

I did however eventually find another site that suggested to create a CSV->table function and just inner join it to the query which works a treat
Go to Top of Page
   

- Advertisement -