question

balaavrdhan avatar image
balaavrdhan asked

else clause of case statement

can we use select statement in else clause of case statement
case
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

what are you trying to achieve? what have you tried so far?
0 Likes 0 ·

1 Answer

·
Matt Whitfield avatar image
Matt Whitfield answered
Yes, but it would usually be pretty inefficient to do so. Here is an example that returns object names and parent object names from the object catalog: SELECT [o].[name] AS ObjectName, CASE WHEN [o].[parent_object_id] = 0 THEN 'None' ELSE (SELECT [o1].[name] FROM [sys].[objects] AS [o1] WHERE [o1].[object_id] = [o].[parent_object_id]) END AS ParentObjectName FROM [sys].[objects] AS [o];
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.