我需要帮助我的科保尔语中我的化学文摘社国际协会发言正确的星号。
Background: What I want this CASE statement to do is to look through the table Concatenated_File and in the column FileID, any row that says File1 , I want it to update the MRNID in the appropriate table, which is titled Load_File_1. And I want to continue the CASE statement that any row that says File2 , I want it to update the MRNID in the appropriate table, Load_File_2.
This is what I have so far, but I can t figure out the correct syntax. Any help would be appreciated. Thanks.
DECLARE @FILEID AS VARCHAR(255)
DECLARE @MRNID AS VARCHAR(255)
DECLARE @UniqueID AS VARCHAR(255)
DECLARE @LNAME AS VARCHAR(255)
DECLARE @FNAME AS VARCHAR(255)
DECLARE @Birthdate AS VARCHAR(255)
DECLARE @SSN AS VARCHAR(255)
DECLARE @HOLD_MRNID AS VARCHAR(255)
DECLARE @HOLD_UniqueID AS VARCHAR(255)
DECLARE @HOLD_LNAME AS VARCHAR(255)
DECLARE @HOLD_FNAME AS VARCHAR(255)
DECLARE @HOLD_Birthdate AS VARCHAR(255)
DECLARE @HOLD_SSN AS VARCHAR(255)
SET NOCOUNT ON
DECLARE curDB CURSOR FAST_FORWARD FOR
-----------------------------------------------
SELECT UniqueID, MRNID, LNAME, FNAME, Birthdate, SSN
FROM Concatenated_File
ORDER BY LNAME, FNAME, Birthdate, SSN
-----------------------------------------------
-- initialize variables
select @FILEID=
select @MRNID=
select @UniqueID=
select @FNAME=
select @LNAME=
select @Birthdate=
select @SSN=
select @HOLD_MRNID=
select @HOLD_UniqueID=
select @HOLD_FNAME=
select @HOLD_LNAME=
select @HOLD_Birthdate=
select @HOLD_SSN=
OPEN curDB
FETCH NEXT FROM curDB into @FILEID, @MRNID, @UniqueID, @FNAME, @LNAME, @Birthdate, @SSN
WHILE (@@FETCH_STATUS = 0)
BEGIN
IF @LNAME = @HOLD_LNAME and @FNAME = @HOLD_FNAME and @Birthdate = @HOLD_Birthdate and @SSN = @HOLD_SSN
BEGIN
select @FILEID
CASE
When @FILEID = File1 Then
Update Load_File1
Set MRNID = @HOLD_MRNID
Where UniqueID = @UniqueID
When @FILEID = File2 Then
Update Load_File2
Set MRNID = @HOLD_MRNID
Where UniqueID = @UniqueID
END
ELSE
BEGIN
select @HOLD_UniqueID = @UniqueID
select @HOLD_MRNID = @MRNID
select @HOLD_FNAME = @FNAME
select @HOLD_LNAME = @LNAME
select @HOLD_Birthdate = @Birthdate
select @HOLD_SSN = @SSN
END
FETCH NEXT FROM curDB into @FILEID, @MRNID, @UniqueID, @FNAME, @LNAME, @Birthdate, @SSN
END
CLOSE curDB DEALLOCATE curDB