Cannot use UPDATE with OUTPUT clause when a trigger is on the table

Visibility Warning: Don’t the other answer. It will give incorrect values. Read on for why it’s wrong. Given the kludge needed to make UPDATE with OUTPUT work in SQL Server 2008 R2, I changed my query from: UPDATE BatchReports SET IsProcessed = 1 OUTPUT inserted.BatchFileXml, inserted.ResponseFileXml, deleted.ProcessedDate WHERE BatchReports.BatchReportGUID = @someGuid to: SELECT BatchFileXml, ResponseFileXml, … Read more

Connecting to MS SQL Server with Windows Authentication using Python?

You can specify the connection string as one long string that uses semi-colons (;) as the argument separator. Working example: import pyodbc cnxn = pyodbc.connect(r’Driver=SQL Server;Server=.\SQLEXPRESS;Database=myDB;Trusted_Connection=yes;’) cursor = cnxn.cursor() cursor.execute(“SELECT LastName FROM myContacts”) while 1: row = cursor.fetchone() if not row: break print(row.LastName) cnxn.close() For connection strings with lots of parameters, the following will accomplish … Read more

Is a single SQL Server statement atomic and consistent?

I’ve been operating under the assumption that a single statement in SQL Server is consistent That assumption is wrong. The following two transactions have identical locking semantics: STATEMENT BEGIN TRAN; STATEMENT; COMMIT No difference at all. Single statements and auto-commits do not change anything. So merging all logic into one statement does not help (if … Read more

SQL Server Connection Strings – dot(“.”) or “(local)” or “(localdb)”

. and (local) and YourMachineName are all equivalent, referring to your own machine. (LocalDB)\instance is SQL Server 2012 Express only. The other parts are depending on how you install – if you install with an instance name – then you need to spell that instance name out (SQL Server Express by default uses the SQLEXPRESS … Read more

T-SQL split string based on delimiter

May be this will help you. SELECT SUBSTRING(myColumn, 1, CASE CHARINDEX(“https://stackoverflow.com/”, myColumn) WHEN 0 THEN LEN(myColumn) ELSE CHARINDEX(“https://stackoverflow.com/”, myColumn) – 1 END) AS FirstName ,SUBSTRING(myColumn, CASE CHARINDEX(“https://stackoverflow.com/”, myColumn) WHEN 0 THEN LEN(myColumn) + 1 ELSE CHARINDEX(“https://stackoverflow.com/”, myColumn) + 1 END, 1000) AS LastName FROM MyTable