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 |
|
acdacd
Yak Posting Veteran
63 Posts |
Posted - 2005-08-19 : 03:58:52
|
| TableA left Join TableBThere exist some row that TableA record exist but col of tableB is null My problem is "When the col of table is null, that's fineBut when col of table is not null, i add some condition (ie where TableB.col1 = 'ABC')"How to do this "if-like" condition?be a hardworking people!! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-19 : 04:09:33
|
| Post table structures, sample and expected dataMadhivananFailing to plan is Planning to fail |
 |
|
|
acdacd
Yak Posting Veteran
63 Posts |
Posted - 2005-08-19 : 04:37:22
|
| CREATE TABLE [dbo].[TestTable2] ( [ID2] [int] IDENTITY (1, 1) NOT NULL , [Info3] [int] NULL ) ON [PRIMARY]GOCREATE TABLE [dbo].[TestTable3] ( [ID3] [int] IDENTITY (1, 1) NOT NULL , [Info3ref] [int] NULL ) ON [PRIMARY]GOALTER TABLE [dbo].[TestTable2] ADD CONSTRAINT [PK_TestTable2] PRIMARY KEY CLUSTERED ( [ID2] ) ON [PRIMARY] GO/*******Data ***/TestTable2 <ID2..Info3 >9 ....8910 ...998TestTable3<ID2...Info3ref>1.......92........9/*****Orginal Query *********/select T2.ID2, T3.ID3 from TestTable2 T2 left join TestTable3 T3 on T2.ID2 = T3.info3refcurrent result<ID2...ID3>9.....19....,210...nullWanted Result:9......210....null(if col ID3 is not null,m then its value must larger then 1)Thxbe a hardworking people!! |
 |
|
|
acdacd
Yak Posting Veteran
63 Posts |
Posted - 2005-08-19 : 04:48:19
|
| Also,If i want count the no of row in TestTable3 that link with each TestTable2ieResult Set<ID......Count of Row>9..........210.........0How to do so ?be a hardworking people!! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-19 : 05:06:25
|
| This will workselect T2.ID2, max(T3.ID3) from TestTable2 T2 left join TestTable3 T3 on T2.ID2 = T3.info3refgroup by T2.ID2For counting, use thisselect T2.ID2, max(isnull(T3.ID3,0)) from TestTable2 T2 left join TestTable3 T3 on T2.ID2 = T3.info3refgroup by T2.ID2MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|