oebanez
oebanez

Reputation: 59

Why Does this TSQL Print Fail?

look, i got a problem, this query doesn't show up the result, but in visual studio, this query is succes (does not error). i want to execute a store procedure that when i execute with kddokter it will show namadokter : nmdokter.

CREATE PROCEDURE lihat_nama
    @kode CHAR(5),
    @nama VARCHAR(30) OUTPUT
    as
    SELECT @nama = nmdokter
    FROM dokter
    WHERE @kode = kddokter


DECLARE @nm VARCHAR(30)
EXEC lihat_nama 'DR002', @nm OUTPUT
PRINT 'Nama Dokter : ' + @nm

Upvotes: 3

Views: 773

Answers (1)

SQLMenace
SQLMenace

Reputation: 135111

Looks like @nm is null, anything + null is null in t-sql

try this

PRINT 'Nama Dokter : ' + isnull(@nm,'')

if @nm is null, you will see just Nama Dokter : printed

also shouldn't it be

EXEC lihat_nama 'DR002',  @nama =@nm OUTPUT

Upvotes: 6

Related Questions