여기에 약간의 테스트 데이터 당신 구문 SQL이에 사용
DECLARE
@InvoiceID int = null,
@InvoiceGUID uniqueidentifier = null,
@CustomerGUID uniqueidentifier = null
SET @InvoiceID = 1000
IF OBJECT_ID ('tempdb..#Invoices') IS NOT NULL DROP TABLE #Invoices
CREATE TABLE #Invoices(
InvoiceID varchar(28),
InvoiceGUID uniqueidentifier,
CustomerGUID uniqueidentifier)
declare @ct int = 0
WHILE @ct < 5
BEGIN
INSERT INTO #Invoices (InvoiceID, InvoiceGUID, CustomerGUID)
SELECT
1000 + @ct as InvoiceID,
NEWID() as InvoiceGUID,
NEWID() as CustomerGUID
SET @ct = @ct + 1
END
--Check your data to see what we filled
SELECT * From #Invoices
--Here we are setting the variable @InvoiceGUID to the GUID for the Invoice which you passed in via @InvoiceID.
--It will overwrite anything that is in the @InvoiceGUID, for example, if you passed something in.
SELECT
@InvoiceGUID = InvoiceGUID
FROM
#Invoices
WHERE
InvoiceID = @InvoiceID
--Check to make sure we got the variable. Also compare this to the table. It should be the same.
SELECT @InvoiceGUID as InvoiceGUIDparameter
--Now set the @CustomerGUID based off the @InvoiceGUID we just selected.
SELECT
@CustomerGUID = CustomerGUID
FROM
#Invoices
WHERE
InvoiceGUID = @InvoiceGUID
--Check the value to compare
SELECT @CustomerGUID as CustomerGUIDparameter
--The only catch here is TSQL batches. Your parameters won't be "global" so to speak if you have mutlple batch statements.
--https://technet.microsoft.com/en-us/library/ms175502(v=sql.105).aspx
--https://msdn.microsoft.com/en-us/library/ms712553(v=vs.85).aspx
1) 예 2) 예. 가정을 테스트하는 데 몇 분을 보내는 것이 더 쉽지 않습니까? 적절한 데이터 유형을 사용하는 경향이 있습니다. 무언가가'guid'라면 - 그것이'uniqueidentifier' 유형의 진짜 안내자가되게하십시오. –
@IvanStarostin 당신은 유효한 가정을 테스트하고, 나의 가정을 테스트하는 것은 좋은 습관입니다. – Austin44