Quantcast
Channel: Answers by "John Franklin"
Browsing all 22 articles
Browse latest View live

Answer by John Franklin

Assuming a temp table named #Grades, here is an example using the UNPIVOT functionality... --- Subjects Failed Per Student SELECT SNO, FAILED_SUBJECTS_COUNT = COUNT(*) FROM ( SELECT SNO, SUB1, SUB2,...

View Article



Answer by John Franklin

Grant beat me to it but I believe you are simply wanting to LEFT JOIN all of your tables ... SELECT T1.ComputerName, T1.Data, T2.Data, T3.Data, T4.Data FROM #TMP1 T1 LEFT JOIN #TMP2 T2 ON...

View Article

Answer by John Franklin

Your description sounds like it could be solved using the PIVOT / UNPIVOT functionality. Without knowing how many subscriptions a customer has you will probably need to use a dynamic solution. Use the...

View Article

Answer by John Franklin

Your dynamic SQL statement does not know about your two date variables. You need to pass those values into the sp_executesql statement similar to the following example... DECLARE @dtStart datetime...

View Article

Answer by John Franklin

The main difference is UNION ALL will include all rows from the multiple recordsets being UNION'd together... Including any duplicates. BOL has a full description at...

View Article


Answer by John Franklin

Your code actually runs successfully for me after I add the alias "S" to the FROM line... However, I am using SQL Server 2005. See below for my running example (of your code). You say this is a...

View Article

Answer by John Franklin

I am not 100% sure I understand your question but here is an attempt at a solution (it does not use PIVOT and has some assumptions about your column types)... I believe you are looking for each...

View Article

Answer by John Franklin

Similar to what Scot said... The answer is yes.However, you have to weigh the positive aspect of encapsulating code that you do not have to duplicate all over your codebase. If you are dealing with a...

View Article


Answer by John Franklin

You can reset the seed value by using the following command... DBCC CHECKIDENT('#tmp', RESEED, 15)Substitute your table name for #tmp and the value you want to set the seed too... Note a value of 15...

View Article


Answer by John Franklin

Example of copying data to a new table and renaming new table to old table... This will allow you to set a new identity increment value (as well as reseed if necessary). --- Initial table CREATE TABLE...

View Article

Answer by John Franklin

You should be able to JOIN back against the CO table to get the slsman from the estimate order... See below for an example... IF OBJECT_ID('tempdb..#CO') IS NOT NULL DROP TABLE #CO CREATE TABLE #CO (...

View Article

Answer by John Franklin

Assuming a temp table named #Grades, here is an example using the UNPIVOT functionality... --- Subjects Failed Per Student SELECT SNO, FAILED_SUBJECTS_COUNT = COUNT(*) FROM ( SELECT SNO, SUB1, SUB2,...

View Article

Answer by John Franklin

Grant beat me to it but I believe you are simply wanting to LEFT JOIN all of your tables ... SELECT T1.ComputerName, T1.Data, T2.Data, T3.Data, T4.Data FROM #TMP1 T1 LEFT JOIN #TMP2 T2 ON...

View Article


Answer by John Franklin

Your description sounds like it could be solved using the PIVOT / UNPIVOT functionality. Without knowing how many subscriptions a customer has you will probably need to use a dynamic solution. Use the...

View Article

Answer by John Franklin

Your dynamic SQL statement does not know about your two date variables. You need to pass those values into the sp_executesql statement similar to the following example... DECLARE @dtStart datetime...

View Article


Answer by John Franklin

The main difference is UNION ALL will include all rows from the multiple recordsets being UNION'd together... Including any duplicates. BOL has a full description at...

View Article

Answer by John Franklin

Your code actually runs successfully for me after I add the alias "S" to the FROM line... However, I am using SQL Server 2005. See below for my running example (of your code). You say this is a...

View Article


Answer by John Franklin

I am not 100% sure I understand your question but here is an attempt at a solution (it does not use PIVOT and has some assumptions about your column types)... I believe you are looking for each...

View Article

Answer by John Franklin

Similar to what Scot said... The answer is yes.However, you have to weigh the positive aspect of encapsulating code that you do not have to duplicate all over your codebase. If you are dealing with a...

View Article

Answer by John Franklin

You can reset the seed value by using the following command... DBCC CHECKIDENT('#tmp', RESEED, 15)Substitute your table name for #tmp and the value you want to set the seed too... Note a value of 15...

View Article
Browsing all 22 articles
Browse latest View live




Latest Images