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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query

Author  Topic 

abbikhan
Starting Member

26 Posts

Posted - 2011-04-26 : 15:10:36
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

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-26 : 15:19:04
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
   

- Advertisement -