Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 643
oebanez Avatar asked Feb 16 '26 19:02

oebanez


1 Answers

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
like image 56
SQLMenace Avatar answered Feb 19 '26 13:02

SQLMenace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!