Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 no return value

Author  Topic 

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-06 : 08:14:36
Hi all. How could i trigger the result in select statement? If the query does not return a value, there must be a prompt message to appear.

thanks
-Ron-

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-06 : 08:19:51
Do it in the front-end.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-06 : 09:05:12
Use @@ROWCOUNT.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-08 : 02:16:29
@@ROWCOUNT?

where can i insert this to my query?
for example.
select lastname from pspersonaldata where dcno ='206756'


thanks
-Ron-
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-08 : 02:27:31
Is this ad-hoc query? or contained in stored proc?

If inside SP, after query check the value of @@Rowcount. If > 0 then there are records else no records. Return appropriate status value (1 or 0 ) back to the caller of the SP and show the message accordingly.

If ad-hoc query, check whether your recordset (or some similar object) on the front-end contain any record and show the message accordingly.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-08 : 02:27:43
quote:
Originally posted by harsh_athalye

Do it in the front-end.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



Yes ! live it up to Madhi's spirit He can't be here but his spirit sure is.


KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-08 : 02:31:48
I see that Madhi's style has haunted you too, Khtan.

[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80235[/url]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-08 : 02:39:15
not ad hoc. i think its stored procedure.

I don't know how to store a value to a variable.

select lastname, @@rowcount as rownumber pspersonaldata where dcno = '111222333'
declare @rowcounter int
set @rowcounter = rownumber

is it right?
thanks.
-Ron-
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-08 : 02:42:59
[code]
declare @rowcounter int
select lastname, @@rowcount as rownumber from pspersonaldata where dcno = '111222333'
set @rowcounter = @@rowcountrownumber
[/code]


KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-08 : 02:44:05
NNNNNoooooooooooooooooooo!!

Create Proc SomeThing
as

declare @count int

select lastname from pspersonaldata where dcno ='206756'
set @count = @@Rowcount

If @count > 0
Return 1
else
Return 0
GO


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-08 : 02:45:15
or if you are only instereted in the number of rows

declare @rowcounter int
select @rowcounter = count(*) from pspersonaldata where dcno = '111222333'



KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-08 : 02:48:41
or even better:

Create Proc SomeThing
as

If Exists(select * from pspersonaldata where dcno ='206756')
Return 1
else
Return 0
GO


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-08 : 02:51:24
KH. It doesnt work. there is no rownumber inside the select statement.
declare @rowcounter int
select lastname from pspersonaldata where dcno = '111222333'
set @rowcounter = @@rownumber



Harsh. I don't know how to use your query/SP. I will try that later if I can't do it in KH's style. But thanks

-Ron-
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-08 : 03:12:55
sorry. it is @@rowcount. I have updated the post


KH

Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-08 : 05:03:27
yes. I got it. What im trying to do now is pass the variable to my windows application. Im halfway for that.
Thanks.
-Ron-
Go to Top of Page
   

- Advertisement -