Rx_
Nothing In Moderation
- Local time
- Yesterday, 18:26
- Joined
- Oct 22, 2009
- Messages
- 2,803
Select Case statement - fragment of a function
How are Nulls handled for both Select Case and return of a Char (string) in T-SQL.
Didn't look like anyone responded just yet.
Forgot - can't use SELECT (with case) inside a scalar function - error message - back to the drawing board!
Have not run this just yet and realize it is a bit verbose.
Just wondering about how a Null is going to be treated in this case.
It is the little things that matter
My plan is to try this and trouble shoot it. Any suggestions are welcome. There always seems to be some innovative option in T-SQL
How are Nulls handled for both Select Case and return of a Char (string) in T-SQL.
Didn't look like anyone responded just yet.
Forgot - can't use SELECT (with case) inside a scalar function - error message - back to the drawing board!
Have not run this just yet and realize it is a bit verbose.
Just wondering about how a Null is going to be treated in this case.
It is the little things that matter
Code:
-- Function not shown, passes in @ID_Wells as argument
DECLARE @SurfaceOwnerID as Int
DECLARE @CharResult as varchar(14)
DECLARE @TestValue INT
set @SurfaceOwnerID = (SELECT Wells_Lease.ID_Wells, Wells_Lease.SurfaceOwnerID
FROM Wells_Lease
WHERE (((Wells_Lease.ID_Wells)=@ID_Wells))
)
SET @TestValue = @SurfaceOwnerID -- Value 1 to 10 including Null
SELECT
CASE @TestValue
WHEN 1 THEN @CharResult = 'First'
WHEN 2 THEN @CharResult = 'Second'
WHEN 3 THEN @CharResult = 'Third'
ELSE @CharResult = Null
END
My plan is to try this and trouble shoot it. Any suggestions are welcome. There always seems to be some innovative option in T-SQL
Last edited: