Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT does not find record
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01682735
Message ID:
01682736
Views:
45
Likes (1)
Hi,

Pleas, put all relevant code.
DECLARE @TestPk INT
declare @testreq char(20)
set @testreq = 'XYZABC123' --  value is 'XYZABC123           ' because datatype is char(20)

SET @TestPk=-1
-- T-SQL engine don't fill @TestPk variable
SELECT  @TestPk = RECORD_PK FROM MyTable WHERE REQUESTOR = @testreq -- no record for this condition
SELECT @@ROWCOUNT -- show: 0
SELECT @TestPk --  show: -1

-- T-SQL engine do fill @TestPk variable
SET @TestPk=(SELECT  RECORD_PK FROM MyTable WHERE REQUESTOR = @testreq) -- no record for this condition
SELECT @@ROWCOUNT -- show: 0
SELECT @TestPk --  show: NULL
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
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform