| Author |
Topic |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2010-09-28 : 13:23:29
|
| Scenariowe have a table that has many columns but we are only concerned about two columns Requestid(not null) and groupno(null).the groupno column has been added to the request table very recently and it cannot be null for the requests going forwardI want to write a stored procedure which when triggered checks a particular requests groupno column and returns 1 if it is not nulland zero when ithe msgn column is null.using this procedure we will be displaying the user an old request form if there is no groupno associated with the request and a new form if there is an groupno value associated to the request |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-09-28 : 13:32:36
|
| SELECT Case WHEN groupno IS NULL Then 0 ELSE 1 ENDFROM yourTableWHERE... |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2010-09-28 : 13:52:35
|
| Iam unable to get the syntax right.can you please validate whehte the below is correctCreate Procedure viewform(@requestid varchar(10),@msgn varchar (10))AS beginselect case WHEN groupno IS NULL Then 0 ELSE 1 ENDFROM requestwhere requestid = @request |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-09-28 : 14:01:09
|
| [code]Create Procedure viewform @requestid varchar(10), @msgn varchar (10)ASselect case WHEN groupno IS NULL Then 0 ELSE 1 ENDFROM requestwhere requestid = @requestid[/code] don't need @msgn in this sample either |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2010-09-28 : 15:02:38
|
| Sorry.the stored procedure needs to be altered in such a way thatI should only pass 1 parameter which is the requestid and I should get the result as '1' or '0'exampleExec viewform requestid and not exec view form requestid,msgn |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2010-09-28 : 15:20:55
|
| perfect.now how do I pass the value of the procedure to a variable |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
|
kevlangdo
Starting Member
5 Posts |
Posted - 2010-09-29 : 08:07:01
|
| To pass the value of the SP to a variablein the SP@SomeVar int outputSet @SomeVar = (select case WHEN groupno IS NULL Then 0 ELSE 1 ENDFROM requestwhere requestid = @requestid)Select @SomeVarin the code (if something like VB.net pr C#) where you are calling the SPIf you are using ADO.Net...OutputParam = DataAdapter.InsertCommand.Parameters.Add("@SomeVar", SqlDbType.Int, 0, "groupno");OutputParam.Direction = ParameterDirection.Output;YourVariable = OutputParam.value;If you are calling from another SPdeclare @somevar int Exec dbo.test @somevarKevin LanguedocSr BI Developerwww.kcodebook.com/wp |
 |
|
|
|