New answers tagged t-sql
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 ...
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)
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
[...
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 ...
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 ...
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-...
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,
...
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) ...
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 [...
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. ...
Top 50 recent answers are included
Related Tags
t-sql × 2909sql-server × 2332
sql-server-2008-r2 × 356
sql-server-2012 × 269
sql-server-2008 × 207
sql-server-2014 × 154
performance × 151
stored-procedures × 150
sql-server-2016 × 144
query-performance × 74
ssms × 71
query × 62
join × 57
trigger × 55
sql-server-2005 × 54
index × 53
dynamic-sql × 51
execution-plan × 48
update × 47
optimization × 45
database-design × 43
pivot × 43
cte × 35
sql-server-2017 × 34
functions × 34