抱歉这个愚蠢的问题,但我对 SQL 很陌生,我正在尝试做一些非常简单的事情。我创建了一个由 3 个表组成的视图,并且效果很好。但是,我要求某些字段使用某种格式的格式。我正在使用 SQL Server Management Studio GUI 创建此视图。
我在视图中有 2 列需要验证:Gender
和DOB
性别包含“M”、“F”或空白,我需要在视图中将其更改为输出'Male'
或'Female'
。
DOB
包含一个未格式化的日期字符串,我需要将其格式化为DD/MM/YYYY
.
我应该在哪里创建这个验证,为了把我所有的卡片都放在桌子上,这里是创建视图脚本:
CREATE VIEW [dbo].[PMIPatient]
AS
SELECT
dbo.refPasPatientRec8Master.Patient_Internal_number AS HospitalNumber,
dbo.refPasPatientRec1Master.[H+C_Number] AS NHSNumber,
dbo.refPasPatientRec1Master.Patient_Title AS Salutation,
dbo.refPasPatientRec1Master.Surname,
dbo.refPasPatientRec1Master.Forenames AS Forename,
dbo.refPasPatientRec1Master.Sex_Code AS Gender,
dbo.refPasPatientRec1Master.Date_of_Birth AS Dob,
dbo.refPasPatientRec1Master.Date_of_Death AS Dod,
dbo.refPasPatientRec1Master.Address_Line_1 AS Address1,
dbo.refPasPatientRec1Master.Address_Line_2 AS Address2,
dbo.refPasPatientRec1Master.Address_Line_3 AS Address3,
dbo.refPasPatientRec1Master.Address_Line_4 AS Address4,
dbo.refPasPatientRec1Master.[Postcode/Pseudo_postcode] AS Postcode,
dbo.refPasPatientRec8Master.Patients_Phone_Number AS Telephone1,
dbo.refPasPatientRec39Master.Work_Telephone_Number AS Telephone2,
dbo.refPasPatientRec1Master.GP_Code AS GPGMCode,
dbo.refPasPatientRec1Master.Death_Indicator AS deceasedFlag
FROM
dbo.refPasPatientRec1Master
INNER JOIN
dbo.refPasPatientRec39Master ON dbo.refPasPatientRec1Master.Patient_Internal_number = dbo.refPasPatientRec39Master.Patient_Internal_number
INNER JOIN
dbo.refPasPatientRec8Master ON dbo.refPasPatientRec1Master.Patient_Internal_number = dbo.refPasPatientRec8Master.Patient_Internal_number