How do you create dynamic fields in a SQL Server table? I'd like to add this to the create table command:
isDeleted = CASE WHEN DeleteDate is null THEN 0 ELSE 1
You're looking to create a computed column .
CREATE TABLE dbo.YourTable (
...
isDeleted AS CASE WHEN DeleteDate IS NULL THEN 0 ELSE 1 END
);
I'm not 100% sure what you mean by dynamic field, but I think this is what you're asking for:
SELECT MyTable.Foo,
CASE WHEN MyTable.Foo = "FOO" THEN
0
ELSE
1
END AS isDeleted
FROM MyTable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.