I have a select query that’s come about from me trying to remove while loops from an existing query that was far too slow. As it stands I first select into a temp table. Then from that temp table I insert into the final table using the values from the temp table. Below is a simplified example of the flow
Tag: sql-server
PowerShell code to script out all SQL Server Agent jobs into a single file
I was trying to script out all the SQL Server Agent jobs for category ‘Data Warehouse’ into a single file I was able to do it using PowerShell, where every single job creates a single file. But I need one file for all the SQL Server Agent jobs under category ID = 100 (or Category : = ‘Data Warehouse’) Code
UNION two SELECT queries but result set is smaller than one of them
In a SQL Server statement there is SELECT id, book, acnt, prod, category from Table1 UNION SELECT id, book, acnt, prod, category from Table2 The first …
SQL Query for multiple joined tables
I am querying against a SQL Server database and I’ve been struggling to get the result set I want. I feel like it is possible but I’m just unable to do it. Here is how the DB is layed out. I’d like to return a result set that looks like this: I’ve unsuccessfully tried using CTE’s: I’ve also unsuccessfully tried
How to remove While loop inside stored procedure in MS SQL Server? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year. Improve this question I have a stored procedure with a cursor inside for the logic which is taking long time for execution . I
Need to match a field with another that has commas on it’ s value
I would like to match the field values of “FORMULATION” from TABLE 1 to “C_TEST_ARTICLE” from table 2, that has mutiple of these formulation sepparated by commas. Table 1: +——–…
Insert row with uniqueidentifier
This is a snippet from a stored proc that creates a database. We have a table with uniqueidentifier PK. I’m trying to insert a row with an empty guid as the PK: The error messages are Can’t see what’s wrong with the VALUES clause but I guess it has something to do with the final quote, although the final quote
Arithmetic overflow error converting nvarchar to data type numeric in case query
I am trying to show the number of quotes won as a percentage of the total number of quotes in a time frame. For example. I have a total of 294 quotes and 173 of them are won. The result I am looking …
Unable to replace the hour in datetime using SQL
Unable to replace the hour part in date-time. The change is reflecting in both hour & year. Please help in rectifying the code. Expected output = 2021-02-13 11:35:32.337 Actual output = 1121-02-13 11:39:11.347 Expected output = 2021-02-13 22:35:32.337 Actual output = 2221-02-13 22:38:13.223 Answer REPLACE(@p, SUBSTRING(@p, 12, 2), ’11’) will replace all occurrences of SUBSTRING(@p, 12, 2) in @p by
Are inner parenthesis needed in the WHERE clause? or anywhere
In the WHERE section or anywhere really where you have multiple conditions like OR’s I know outer parenthesis are required but are the inner ones? For example my assumption is that Is the same as writing However if we remove the outer parenthesis then I know the query will be different. Example: And Are both the same thing but not