-7

I write the following code to print message:

declare @NT1 int
set @NT1 =(SELECT   CompanyID  FROM dbo.CompanyInfo where CompanyID = 101)

if @NT1> 101

print 'Good'

After execute this script , I get the following message Command(s) completed successfully.

I should get message 'Good' after executing the above script. How do I print message?

Thanks

3
  • 3
    Why would it print "Good"? Last time I checked, 101 is not > 101. Jul 29, 2016 at 18:49
  • 2
    Oh Gosh!!! How can you get a value more than 101 when you filtered for 101?
    – techspider
    Jul 29, 2016 at 18:50
  • That's on sql server. This question is about sql sql server.
    – stark
    Jul 29, 2016 at 18:54

2 Answers 2

0

One solution:

declare @NT1 int
set @NT1 =(SELECT   CompanyID  FROM dbo.CompanyInfo where CompanyID = 101)

if @NT1 = 101

print 'Good'
-2

Forgot else statement:

declare @NT1 int

set @NT1 =(SELECT CompanyID FROM dbo.CompanyInfo where CompanyID = 101)

if @NT1 > 101 print 'good'

ELSE
PRINT 'bad';

Not the answer you're looking for? Browse other questions tagged or ask your own question.