Click here to Skip to main content
16,010,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want create a table on MSSQL that have 3 case; true, false, null. How can create
Formula of "Computed Column Specification" area?
Thanks.

CREATE TABLE [dbo].[Table_2](
	[Order] [int] IDENTITY(1,1) NOT NULL,
	[thickCase] [bit] NULL,
	[thick_Case]  AS (case [thickCase] when NULL then 'Fixed' else case [thickCase] when (1) then 'Up' else 'Down' end end),
 CONSTRAINT [PK_Table_2] PRIMARY KEY CLUSTERED 
(
	[Order] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO


What I have tried:

[thick_Case]  AS (case [thickCase] when NULL then 'Fixed' else case [thickCase] when (1) then 'Up' else 'Down' end end)
Posted
Updated 18-Mar-21 21:46pm

1 solution

Try:

SQL
[thick_Case] AS
    (
      CASE
        WHEN COALESCE([thickCase], -1) = 1 THEN 'Up'
        WHEN COALESCE([thickCase], -1) = 0 THEN 'Down'
        ELSE 'Fixed'
      END
    ),


See: SQL Server 2019 | db<>fiddle[^]
 
Share this answer
 
v2
Comments
gacar 19-Mar-21 7:29am    
Worked! Many thanks.
Maciej Los 19-Mar-21 8:40am    
You're very welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900