Would someone help me understand the details of the error below..? This is for SQL Server 2008. I did fix it myself, and found many search hits which show the same fix, but none explain WHY this happens in a CTE. Types don’t match between the anchor and the recursive part in column “txt” of recursive query “CTE”. Here is
Tag: tsql
T-SQL : Alter Database statement inside IF is failing
We have a scenario where we have to change database compatibility based on SQL Server version and we have written below condition for the same. In one of our customer’s server this code is failing with below error and the server has SQL Server 2014 Msg 15048, Level 16, State 1, Line 4 Valid values of the database compatibility level
Can I use a CTE to make these two tables become one?
Is there any way I can make these two queries become one query? I need all of this to be in one table. Currently I’m not using any common table expression and I believe if I use them I can make these two codes into one single table. I would also like a column called ‘G’ which is a sum
How to get NULL or Zero values in SQL Server results set
Trying to get the output of all mentioned accounts(total of 9) even though there are no existing records for the GB.periode = 11 Tried using ISNULL(SUM(GB.bdr_val), 0) but still I’m only getting output for GB.reknr = 5210 OR GB.reknr = 5211 OR GB.reknr = 5250 OR GB.reknr = 5340. I have a sample DB layout below, I still need the
Grouping rows over common data in a column and min max start/end date via cursor fetch method
I have a stored procedure with a couple of input parameters Input parameters: Result set: AuxTable is not the final intended table, it’s just being displayed for debugging/troubleshooting. MsgLinkId MyRowId WO_ID SourceUnitName MaterialName BatchID UnitofMeasure Segment1 Segment2 Segment3 Segment4 Segment5 Amount StartDate EndDate 5 1 731000037 B1S01C03 RAW MILK 0 KGM B1S01W32 NONE NONE NONE NONE 13391.7524414063 2022-01-01 14:22:25.773 2022-01-01
Self join to update table in SQL
I have the following table: Category Qty Orders Level Product 0 Part 1 2 4 1 Part 2 3 5 1 Part 1.1 4 6 2 Part 1.2 5 7 2 How can I update the above table’s Level 0 row with sum of Qty and Orders (excluding Level 0’s Qty and Orders)? i.e. Category Qty Orders Level Product 14
Dynamic SQL – Use declared VARCHAR in SET SQL string
How to use the declared variable @CodeID inside the SQL string? When I run following statement I get the “Invalid object name (..)” error. Answer It looks to me that you need two levels of dynamic SQL, with the first level inserting the database name (from #folders), and the second level inserting a constructed table name (based on the CodeType
SQL Query to merge several views into one
I was trying to create a new view out of 3 or 4 other views/tables. TableA: title_id homeTeam 1234 WSV 5678 SSV 7890 NULL 4321 SCC TableB: title_id awayTeam 1234 SSV 5678 SFV 7890 NULL 4321 KFC TableC: title_id homeTeam 1234 SSV 5678 NULL 7890 AAB 4711 BFG I would like to generate a new view out of those three
TSQL – Fill in missing values as 0 for dates without a value
Apologies in advance for the pictures. I did these up as tables in Stack and they displayed fine in Preview but would not display properly once published. I have a sample dataset like below with many more KPIs. Picture Of Tables The dataset currently returned is just a join of these 2 tables and returns date instead of Date ID,
Executing stored procedure via linked server through trigger
I have created a linked server on a SQL Server connecting to an Azure SQL datawarehouse. When I execute a stored procedure of SQL DW via SSMS as below, it is getting executed as expected. But when I try to have that stored procedure executed as a part of trigger definition And when I try to insert a record into