i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where to write where condition sql query using cte
08-20-2013, 06:44 AM
Post: #1
Not Solved where to write where condition sql query using cte
DECLARE @RNO BIGINT =2
;with cte
as (
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1)
) AS [Row number],
[Organisation Region] AS [Service Provider region],
[Request Status] AS [Request status],
COUNT([Request Status]) AS [Total numbers]--,
FROM vwRequestStatusDetail
WHERE [Organisation Region] IS NOT NULL

GROUP BY [Organisation Region],
[Request Status]
)
SELECT * FROM cte
--where (@RNO IS NULL) OR ([Row number] = @RNO)
UNION
SELECT '' AS [Service Provider region],'','Total',sum([Total numbers]) FROM cte
--where (@RNO IS NULL) OR ([Row number] = @RNO)
ORDER BY [Row number] DESC


in above script i was writing whre two time ,instead how can i do other ways with one time calling of where condition



“A mind stretched by a new idea can never go back to its original dimension.”

Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  how to view Response.Write to textbox in asp.net dn2010 0 5,114 10-28-2015 02:34 PM
Last Post: dn2010
  what is best way to put where condition it may be null or may be value praveen 2 924 08-22-2013 10:52 AM
Last Post: praveen
  sql query formation praveen 5 1,401 08-19-2013 07:47 AM
Last Post: magnum_2007
  need to write function in sql praveen 1 2,164 07-23-2013 12:30 PM
Last Post: praveen
  sql query check praveen 6 2,047 01-16-2013 12:15 PM
Last Post: praveen



User(s) browsing this thread: 1 Guest(s)