Hi Martina,
Thank you for your prompt reply. I didn't know that SQL does not fill the value of the variables if the SQL Select does not find a record.
>Hi,
>
>Pleas, put all relevant code.
>
>
>DECLARE @TestPk INT
>declare @testreq char(20)
>set @testreq = 'XYZABC123'
>
>SET @TestPk=-1
>
>SELECT @TestPk = RECORD_PK FROM MyTable WHERE REQUESTOR = @testreq
>SELECT @@ROWCOUNT
>SELECT @TestPk
>
>
>SET @TestPk=(SELECT RECORD_PK FROM MyTable WHERE REQUESTOR = @testreq)
>SELECT @@ROWCOUNT
>SELECT @TestPk
>
>
>
>MartinaJ
>
>>Hi,
>>
>>I realize that this is a very newbie question. But I would like to know why or at least to know that I understand this correctly.
>>
>>The following SQL Select should find a record.
>>
>>
>>declare @testreq char(20)
>>set @testreq = 'XYZABC123'
>>SELECT @TestPk = RECORD_PK FROM MyTable WHERE REQUESTOR = @testreq
>>
>>
>>The value assigned to the variable @TestPk is 0 (zero) (since the record not found in the table).
>>
>>Why not NULL? Is this because at the top of the stored procedure the @TestPk is declared as an INT and it cannot be NULL?
>>
>>TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham