July 19, 2017 at 8:55 am
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE
If you were to save the string beginning 'CREATE PROCEDURE...' to a variable then examine it using PRINT, you would see where it all goes terribly wrong, at the single quote pairs designating empty strings: '' as MGCTag, '' as Description
I'd recommend you do exactly that, because it can be fiendishly difficult figuring out exactly how many escape quotes to use.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 19, 2017 at 11:06 am
ChrisM@Work - Wednesday, July 19, 2017 8:55 AMEXEC dbo.sp_executesql @statement = N'CREATE PROCEDUREIf you were to save the string beginning 'CREATE PROCEDURE...' to a variable then examine it using PRINT, you would see where it all goes terribly wrong, at the single quote pairs designating empty strings: '' as MGCTag, '' as Description
I'd recommend you do exactly that, because it can be fiendishly difficult figuring out exactly how many escape quotes to use.
That didn't even occur to me that the single quotes were the problem. Solved it by doing it as: NULL as MGCTag, etc. Thanks for the heads up, I really appreciated you getting my brain going. π
July 19, 2017 at 11:25 am
anthonylinhardt 9768 - Wednesday, July 19, 2017 11:06 AMChrisM@Work - Wednesday, July 19, 2017 8:55 AMEXEC dbo.sp_executesql @statement = N'CREATE PROCEDUREIf you were to save the string beginning 'CREATE PROCEDURE...' to a variable then examine it using PRINT, you would see where it all goes terribly wrong, at the single quote pairs designating empty strings: '' as MGCTag, '' as Description
I'd recommend you do exactly that, because it can be fiendishly difficult figuring out exactly how many escape quotes to use.That didn't even occur to me that the single quotes were the problem. Solved it by doing it as: NULL as MGCTag, etc. Thanks for the heads up, I really appreciated you getting my brain going. π
But selecting an empty string ('') is not the same as selecting a NULL, so the queries in the stored procedure have changed.
SELECT CASE WHEN NULL = '' THEN 'Match' ELSE 'No Match' END;
It's no problem to query NULLs; just make sure this is really what you want to do.
Viewing 3 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply