Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

abbikhan
Starting Member

26 Posts

Posted - 04/26/2011 :  15:10:36  Show Profile  Reply with Quote
SELECT DISTINCT t2.appID,t2.[name]
FROM (
SELECT DISTINCT AA1.pid
FROM tableAA1 AS AA1 INNER JOIN (SELECT MAX(ID) AS ID
FROM tableAA2
GROUP BY pID) AS SIp
ON AA1.ID=SIp.ID INNER JOIN stable AS St ON St.id=AA1.SID
WHERE St.id NOT IN (5,8,9) AND AA1.coluBy2 < @coluBy3
)AS A
INNER JOIN table1 As t1
ON t1.id=A.pid INNER JOIN table2 AS t2 ON t2.ID=t1.sID
INNER JOIN table3 AS t3 ON t2.ID=t3.stID
WHERE coluBy=@coluBy


i have same query for another part in which i have @coluBy3 with
different parameter value and also joins ( INNER JOIN table1 As t1
ON t1.id=A.pid INNER JOIN table2 AS t2 ON t2.ID=t1.sID
INNER JOIN table3 AS t3 ON t2.ID=t3.stI) with some more tables like table1 and table2 from them + table6

problem is :
how can i combine them in a single sp as some times user wan to have results form both parts or some time from one only

help me in it please

Edited by - abbikhan on 04/26/2011 17:12:50

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 04/26/2011 :  15:19:04  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Define the parameters as optional and

WHERE coluBy=@coluBy
or coluBy=@coluBy3

Then if a parameter is null then that part of the where clause will be ignored.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000