ListAGG in SQLSERVER

Starting in SQL Server 2017 the STRING_AGG function is available which simplifies the logic considerably: See SQL Fiddle with Demo In SQL Server you can use FOR XML PATH to get the result: See SQL Fiddle with Demo

SQL “select where not in subquery” returns no results

Update: These articles in my blog describe the differences between the methods in more detail: NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: SQL Server NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: PostgreSQL NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: Oracle NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: MySQL There are three ways to do such a query: LEFT JOIN … Read more

SQL Server Linked Server Example Query

The format should probably be: For example: DatabaseServer1.db1.dbo.table1 Update: I know this is an old question and the answer I have is correct; however, I think any one else stumbling upon this should know a few things. Namely, when querying against a linked server in a join situation the ENTIRE table from the linked server will likely be downloaded … Read more

SQL – WHERE (X, Y) IN (A, B)

Why not something simple like the following? WHERE (X = 1 AND Y = 2) OR (X = 5 AND Y = 6) … Or, if you’re looking for rows (based on your example) where Y should be X + 1, then: WHERE Y = X + 1 If you have thousands of OR clauses like the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)