Following is my query:
SELECT 'INSERT INTO MyTable (
CancellationReason
)
VALUES (
''' + rc.CancelReason + '''
)'
FROM AnotherTable a
I get below result:
Since the column a.CancelReason is nullable, you see NULL values in the result set. But I need the result something like this (I need a string representation in place of NULL (basically an insert statement in the current example)):
I tried something like this but no help:
SELECT 'INSERT INTO MyTable (
CancellationReason
)
VALUES (
''' + ISNULL(a.CancelReason, null) + '''
)'
FROM AnotherTable a
Could you please suggest?


ISNULL(a.CancelReason, 'null')(notice thatnullis a string-literal in this case, not a literalnull.