Quantcast
Channel: Need T-SQL query
Browsing latest articles
Browse All 8 View Live

Need T-SQL query

Try this querySELECT Code,Status,COUNT(*)FROM StateGROUPBY Code,StatusUnionSELECT Code,Status,COUNT(*)FROM StateGROUPBY Code,Statuswhere Code=XYZ andstatus <>0

View Article


Need T-SQL query

declare @t TABLE (Code NVARCHAR(10),Status int) INSERT INTO @t values ('ABC', 0) INSERT INTO @t values ('ABC', 0) INSERT INTO @t values ('ABC', 1) INSERT INTO @t values ('XYZ', 1) INSERT INTO @t values...

View Article


Need T-SQL query

Try this Query , it will match all your status(Select CODE,STATUS,COUNT(1) from STATEGROUP BY CODE,STATUS)UNION ALL(Select DISTINCT CODE , STATUS=0, 0 FROM STATE AWHERE NOT EXISTS(Select 1 from STATE...

View Article

Need T-SQL query

Unless you have a lookup table for codes and statuses, then you can use:;with CS as(select     C.code, S.statusfrom    (select distinct code from state) as C    cross join    (select 0 as status union...

View Article

Need T-SQL query

That was my question.Try the following;WITH CTE AS ( SELECT Code,Status,COUNT(Status) AS Coun,ROW_NUMBER() OVER(PARTITION BY Code ORDER BY Code) AS Row FROM State GROUP BY Code,Status ) SELECT...

View Article


Need T-SQL query

this query doesn't returnCode Status  CountXYZ   0          0Thanks, Loonysan | http://mystutter.blogspot.com

View Article

Need T-SQL query

So, you need to create a record for XYZ if 0 doesn't exist or the following is what you need?SELECT Code,Status,COUNT(Status) FROM State GROUP BY Code,StatusAbdallah El-Chal, PMP, ITIL, MCTS

View Article

Need T-SQL query

I have a table with the following fields CREATE TABLE state (Code NVARCHAR(10),Status int)INSERT INTO State values ('ABC', 0) INSERT INTO State values ('ABC', 0) INSERT INTO State values ('ABC', 1)...

View Article

Browsing latest articles
Browse All 8 View Live