Skip to content

Instantly share code, notes, and snippets.

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 CheetahChrome/865bee16a959c58e5da165806ae0413e to your computer and use it in GitHub Desktop.
Save CheetahChrome/865bee16a959c58e5da165806ae0413e to your computer and use it in GitHub Desktop.
SQL Server: Read Target Table and create a Declare statement usable in a stored procedure
SELECT
COLUMN_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
concat('DECLARE @', COLUMN_NAME, N' ', DATA_TYPE,
IIF(CHARACTER_MAXIMUM_LENGTH IS not null
, CONCAT(N' (', CHARACTER_MAXIMUM_LENGTH, N')')
, N''
)
) AS [declare]
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Address'
@CheetahChrome
Copy link
Author

The address Table:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment