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.
Author |
Topic |
abbikhan
Starting Member
26 Posts |
Posted - 2011-04-26 : 15:10:36
|
SELECT DISTINCT t2.appID,t2.[name]FROM (SELECT DISTINCT AA1.pidFROM tableAA1 AS AA1 INNER JOIN (SELECT MAX(ID) AS IDFROM tableAA2 GROUP BY pID) AS SIpON AA1.ID=SIp.ID INNER JOIN stable AS St ON St.id=AA1.SIDWHERE St.id NOT IN (5,8,9) AND AA1.coluBy2 < @coluBy3)AS AINNER JOIN table1 As t1ON t1.id=A.pid INNER JOIN table2 AS t2 ON t2.ID=t1.sIDINNER JOIN table3 AS t3 ON t2.ID=t3.stIDWHERE coluBy=@coluByi have same query for another part in which i have @coluBy3 withdifferent parameter value and also joins ( INNER JOIN table1 As t1ON t1.id=A.pid INNER JOIN table2 AS t2 ON t2.ID=t1.sIDINNER 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 andWHERE coluBy=@coluByor coluBy=@coluBy3Then 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. |
|
|
|
|
|