Re: Counting and IF statements
Nasser: Ok, what I did was changed your SQL to;UPDATE t1SET DeviceType1 = (selectCount(t4.DeviceType)from t2 left join t3 on t2.LicenseNum= t3.LicenseNum left join T4 on T3.DeviceCode=...
View ArticleRe: Counting and IF statements
Nasser: This got me a perfect list of the counts and everything, but how would I update the T1.DeviceType1 and T1.DeviceType2 with the counts?
View ArticleRe: Counting and IF statements
Try this sampleDeclare @T1 as table(TransId numeric(18,0),DeviceType1 nvarchar(50),DeviceType2 nvarchar(50)); Declare @T2 as table(TransId numeric(18,0),LicenseNum nvarchar(50)); Declare @T3 as...
View ArticleRe: Counting and IF statements
See following with T4CREATE TABLE T1( TransId int NOT NULL, DeviceType1 int NOT NULL, DeviceType2 int NOT NULL) Insert into T1 (TransId, DeviceType1, DeviceType2) Values(999999999,0,0) CREATE TABLE T2(...
View ArticleRe: Counting and IF statements
Nasser: yours is close, but I messed up. I actually have 1 more Table T4 which is the one with the Device Type on it.I have 4 tables; T1, T2, T3, T4. T1 has (TransId, DeviceType1, DeviceType2). T2 has...
View ArticleRe: Counting and IF statements
See the pages below;http://www.codeproject.com/Articles/265371/Common-Table-Expressions-CTE-in-SQL-SERVER-2008http://msdn.microsoft.com/en-us/library/ms190766(v=sql.105).aspxHope this helps.
View ArticleRe: Counting and IF statements
You can use following query to get your desired resultCREATE TABLE T1( TransId int NOT NULL, DeviceType1 int NOT NULL, DeviceType2 int NOT NULL) Insert into T1 (TransId, DeviceType1, DeviceType2)...
View ArticleRe: Counting and IF statements
Try:with CTE_Q as ( select t2.TransId, COUNT(case when t3.DeviceType = 1 then 1 end) as DeviceType1, COUNT(case when t3.DeviceType = 2 then 1 end) as DeviceType2 from T2 inner join T3 on t3.LicenseNum...
View ArticleCounting and IF statements
I have 3 tables; T1, T2, T3. T1 has (TransId, DeviceType1, DeviceType2). T2 has (TransId, LicenseNum). T3 has (LicenseNum, DeviceType)What I'm trying to do is join T2 and T3 on the LicenseNum field and...
View Article
More Pages to Explore .....