Skip to main content

Posts

Showing posts from October, 2018

MS SQL Server loop through a list of strings

SQL Server does not have a straight forward way to do a For Loop with a list of string values. The easiest solution I found, can be seen below: DECLARE @ list varchar ( 8000 ) DECLARE @pos INT DECLARE @ len INT DECLARE @ value varchar ( 8000 ) SET @ list = 'A101,A203,B12341,C124,' set @pos = 0 set @ len = 0 WHILE CHARINDEX ( ',' , @ list , @pos+ 1 )> 0 BEGIN set @ len = CHARINDEX ( ',' , @ list , @pos+ 1 ) - @pos set @ value = SUBSTRING (@ list , @pos, @ len ) PRINT @ value -- for debug porpose --DO YOUR MAGIC HERE set @pos = CHARINDEX ( ',' , @ list , @pos+@ len ) + 1 END Please check the original website: https://www.admfactory.com/split-a-string-and-loop-in-sql-server/

Use windows authentication out of the domain

You don't need to have your computer on the domain to use Windows Authentication. Just use the runas command (tested on Windows 10 Home) This is my SQL Server Management Studio shortcut: "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe"  Create a copy of the shortcut and change the target, adding the following to the beginning: %windir%\System32\runas.exe /netonly /user:domain\username  The full target in my shortcut looks like this: %windir%\System32\runas.exe /netonly /user:domain\username "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe" Notice that I also changed the Shortcut Name to Windows Authentication and the icon as well   When I double click the new shortcut, I'm asked for my domain user password And once I'm authenticated, I can open a database using Windows Authentication.