Author |
Topic |
niyaz4872
Starting Member
41 Posts |
Posted - 2013-01-10 : 03:13:19
|
following is my table structureid count01 204 109 5following is sample results i wan'tid count01 202 003 004 105 006 007 008 009 510 0 |
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2013-01-10 : 03:19:36
|
use Right Join Or LefJoin in your querycould u put your entire query? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 03:20:37
|
does id values come from a master table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
niyaz4872
Starting Member
41 Posts |
Posted - 2013-01-10 : 03:26:56
|
yes .and max id is ten |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 03:31:12
|
then you can do likeSELECT m.id,COALESCE(t.[count],0) AS [count]FROM MasterTable mLEFT JOIN YourTable tON t.id = m.id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
niyaz4872
Starting Member
41 Posts |
Posted - 2013-01-10 : 03:40:01
|
tnx.if id does not values come from a master table?results i wan't |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 03:40:58
|
Are you telling that you need to generate id on the fly?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
niyaz4872
Starting Member
41 Posts |
Posted - 2013-01-10 : 03:43:04
|
yes |
|
|
niyaz4872
Starting Member
41 Posts |
Posted - 2013-01-10 : 03:44:37
|
i don't master table |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 03:46:22
|
then how will you decide on upper limit? will it be always 10?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
niyaz4872
Starting Member
41 Posts |
Posted - 2013-01-10 : 03:48:16
|
yes |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 03:53:32
|
[code];With NumberTable(N)AS(SELECT 1UNION ALLSELECT N + 1FROM NumberTableWHERE N + 1 <= 10)SELECT n.N,COALESCE(t.[count],0) AS [count]FROM NUmberTable nLEFT JOIN YourTable tON t.id = n.N[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
niyaz4872
Starting Member
41 Posts |
Posted - 2013-01-10 : 04:09:11
|
tnx |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 04:13:06
|
wlcm------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|