New answers tagged

0 votes

Insert in to table without duplicate records TSQL

You could also get it using except. drop table if exists table1 go create table table1(id int, name char(1), pin int) go drop table if exists table2 go create table table2(id int, name char(1), pin ...
user avatar
0 votes

Row_number to not increment if values on three columns are the same from the row before

Based on your description, what you want should be dense_rank() over (partition by orderid order by DocumentNo_, CurrentPackageTrackingNo)
user avatar
  • 465
2 votes
Accepted

Generate JSON with property names that include dot using SELECT FOR JSON

You can use FOR JSON AUTO which ignores . characters in keys. In this case, you need to place it in a subquery, otherwise you cannot get the value key SELECT [Id], JSON_QUERY(( SELECT [...
user avatar
  • 5,194
1 vote

Generate JSON with property names that include dot using SELECT FOR JSON

One solution (in addition to my other answer) is to be a bit more explicit in the JSON structure you wish to generate. Basically, here you are providing FOR JSON with some already properly-parsed ...
user avatar
  • 963
0 votes

Generate JSON with property names that include dot using SELECT FOR JSON

One solution is to create your own escape sequence, and then use procedural T-SQL with @variables, rather than pure relational query language. Given the inability to directly escape characters in ...
user avatar
  • 963
1 vote

Setting up reporting and alerting in SQL Server through TSQL and Powershell

Create agent event alert for the errors that are written to the event log. Here's a util I did that generates a bunch, and can serve as a starting point. https://karaszi.com/agent-alerts-management-...
user avatar
0 votes
Accepted

SQL query to group results on matching record ID

You should be able to accomplish your goal with something like the following: SELECT DISTINCT InputPersons.PersonId AS InputPersonId, MatchedPersons.PersonId AS MatchedPersonId, ...
user avatar
  • 24k
1 vote
Accepted

Must declare the scalar variable "@Name"

I fixed your code and reformatted it. DROP TABLE IF EXISTS #linkedservers; CREATE TABLE #linkedservers ( SRV_NAME sysname NULL, SRV_PROVIDERNAME nvarchar(128) NULL, SRV_PRODUCT nvarchar(128) ...
user avatar
  • 12.2k
0 votes

Must declare the scalar variable "@Name"

This is probably cleaner using sys.master_files which shows the files for all databases: /*building up dynamic sql*/ SET @Statement =N' SELECT name AS [DataFileName], physical_name AS [...
user avatar
  • 1,450
3 votes

ownership chaining not working with sp_cursorfetch

This appears to be peculiar to keyset cursors, where ownership chaining does not work as expected for scalar functions in the fetch portion of the cursor plan. The issue is not limited to API cursors. ...
user avatar
  • 69.1k

Top 50 recent answers are included