Jeff S
asked on
Insert Record if no records found - SQL
I need to insert a record if no records exist. In my example below, It returned no records; therefore I need it to return the current date for the created, for CreatedBy it can be 'N/A' and Description equal to 'No Correspondence Notes'.
DECLARE @PATIENTVISITID INT = 695
SELECT
pc.Created
, ISNULL ( NULLIF ( REPLACE ( pc.CreatedBy , CHAR ( 0 ) , '' ) , '' ) , 'System' ) AS CreatedBy
, CASE
WHEN pc.Description = '**long**' THEN pc.DescriptionLong
ELSE pc.Description
END AS Description
FROM PatientCorrespondence pc
WHERE pc.PatientVisitID = @PATIENTVISITID;
ASKER
Yes, PatientVisitId is the PK.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks!
Try:
Open in new window