EN VI
Posts (0)
Questions (19)
2024-03-10 22:30:04
Like this declare @sql nvarchar(max) = 'select * from sys.objects' declare @forJsonSql nvarchar(max) = concat('select @json = (',@sql, ' for json auto)') --print @forJsonSql declare @json nvarchar(...
Tags: sql-server t-sql
2024-03-10 22:30:05
You can't use arbitrary statements in the THEN part of a MERGE, the syntax is quite specific about what you are allowed to do. If you want to THROW on such rows then just use a IF EXISTS... WHERE NOT...
Tags: sql sql-server t-sql
2024-03-11 05:00:08
You can retrieve a whole JSON object or array in the OPENJSON WITH schema, by using nvarchar(max) AS JSON. Then you can CROSS APPLY OPENJSON feeding that JSON into the next call, and so on. Do note th...
Tags: arrays json sql-server
2024-03-11 09:00:07
The problem is that you have a self-referencing foreign key, which is preventing you deleting this row because there are child rows dependent on it. The UPDATE statement isn't helping as that will onl...
Tags: c# sql sql-server
2024-03-12 08:00:04
Something like this mayhaps: DECLARE @cols AS NVARCHAR(MAX), @cols2 NVARCHAR(MAX), @sql AS NVARCHAR(MAX); SELECT * INTO #data FROM ( VALUES (1, N'A', N'H', N'J') , (2, N'B', N'I', N...
Tags: sql sql-server pivot
2024-03-12 12:00:08
I have a query where I am checking for the first instance of a status. Seems like you're checking for the latest instance of a status. It seems like the problem statement can be simplified to: Find...
Tags: sql sql-server
2024-03-12 14:30:06
We can take a union of the two tables and then aggregate by name: SELECT name, id, GROUP_CONCAT(course) AS courses -- see note below FROM ( SELECT name, id, course FROM TableA UNION ALL S...
Tags: sql sql-server
2024-03-12 22:00:11
Perhaps these FILLFACTORs have been automatically generated by the SQL server. Perhaps. And if so, there's no need to version them. You version enough to recreate the project entirely from the repos...
Tags: sql-server git t-sql
2024-03-13 00:00:08
As clearly shown in the error message, you can't use window functions directly in an UPDATE, you need a subquery. But you can update the subquery directly, no need to join. WITH cte AS ( SELECT *,...
Tags: sql sql-server
2024-03-13 05:30:04
This will easily fit as a single UPDATE query, with no need to ever pull any data back to C# for processing. I don't see a source for the profitpercentage variable in C#. I expect this was intended to...
Tags: c# sql-server

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login