Created
December 14, 2015 05:08
-
-
Save kiyokura/2067949821ae6020d023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN | |
DECLARE @A AS VARCHAR(MAX) = NULL | |
DECLARE @B AS VARCHAR(MAX) | |
-- パターン1:先に結合した文字列を作ってからEXECUTEに渡す | |
SET @B = 'SELECT ''' + @A + ''' AS COL1' | |
EXECUTE(@B) | |
-- パターン2:EXECUTEの引数内で+演算子で結合? | |
EXECUTE('SELECT ''' + @A + ''' AS COL1') | |
-- ========================================= | |
-- 結果 | |
-- ========================================= | |
-- パターン1: @BがNULLのため何も結果が得られない | |
-- パターン2: @Aを空文字列として組み立てられた「SELECT '' AS COL1」が実行される | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment