Skip to content

Instantly share code, notes, and snippets.

@kwestground
Created January 19, 2022 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwestground/6ea6bb4c301c4c0c0b9cfa033c50ba20 to your computer and use it in GitHub Desktop.
Save kwestground/6ea6bb4c301c4c0c0b9cfa033c50ba20 to your computer and use it in GitHub Desktop.
DECLARE @Table nvarchar(100) = 'MyTableName'
SELECT 'REPLACE(''INSERT INTO ['+@Table+'] (' +
STUFF ((
SELECT ', [' + name + ']'
FROM syscolumns
WHERE id = OBJECT_ID(@Table) AND
name <> 'me'
FOR XML PATH('')), 1, 1, '') +
') VALUES (' +
STUFF ((
SELECT
'] AS nvarchar(MAX)), ''NULL'') + '''''', '''''' + ISNULL(CAST([' + name
FROM syscolumns
WHERE id = OBJECT_ID(@Table) AND
name <> 'me'
FOR XML PATH('')), 1, LEN('] AS nvarchar(MAX)), ''NULL'') + '''''', '), '') + '] AS nvarchar(MAX)), ''NULL'') + '''''')'', ''''''NULL'''''', ''NULL'')'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment