Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 25th, 2004, 01:25 AM
Authorized User
 
Join Date: Nov 2003
Location: , Israel, .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default select case

Hi all,

I have a trigger in which I retrive a certain value into a veriable.
Then based on the value of this variable I want to set the values of two other veriables (i.e. if variable=1 then variable1=10,variable2=20;if variable=2 then variable1=34,variable2=46).
I want to use something like select case clause.
These are the variables :

SELECT @contractType = (SELECT fldID FROM Deleted)

DECLARE @generalTemplateID int
DECLARE @alertsTemplateID int

how do I do it ?

Thanks,


Yuval Kronenfeld
Web Developer
__________________
Yuval Kronenfeld
Israel
  #2 (permalink)  
Old August 25th, 2004, 08:37 AM
Authorized User
 
Join Date: Jul 2004
Location: cleveland, oh, USA.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

declare @contractType as int
DECLARE @generalTemplateID int
DECLARE @alertsTemplateID int

SELECT @contractType = (SELECT fldID FROM Deleted)

CASE @contractType
     when x then set @generalTemplateID = value1
     when y then set @alertsTemplateID = value2
     else then (something else)
END

  #3 (permalink)  
Old August 25th, 2004, 10:14 AM
Authorized User
 
Join Date: Nov 2003
Location: , Israel, .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gracias!

Yuval Kronenfeld
Web Developer
  #4 (permalink)  
Old August 25th, 2004, 01:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by dhay1999
 declare @contractType as int
DECLARE @generalTemplateID int
DECLARE @alertsTemplateID int

SELECT @contractType = (SELECT fldID FROM Deleted)

CASE @contractType
     when x then set @generalTemplateID = value1
     when y then set @alertsTemplateID = value2
     else then (something else)
END
That won't work.

In T/SQL, CASE is an expression which returns a value and is not a flow control construct as in other languages.

You'll have to execute IF/ELSE statement blocks to do what you want.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
  #5 (permalink)  
Old August 25th, 2004, 02:33 PM
Authorized User
 
Join Date: Nov 2003
Location: , Israel, .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,

Well actually i already figured it out myself:

declare @contractType as int
DECLARE @generalTemplateID int
DECLARE @alertsTemplateID int

SELECT @contractType = (SELECT fldID FROM Deleted)

SELECT @alertsTemplateID =
CASE @contractType
     when 1 then set value1
     when 2 then set value2
END

and the same for the second variable.
Thank you all anyway



Yuval Kronenfeld
Web Developer


Similar Threads
Thread Thread Starter Forum Replies Last Post
select case bacster Classic ASP Basics 2 May 1st, 2006 06:31 PM
Select Case junaidraja30 Access VBA 1 February 5th, 2005 08:30 PM
Select Case morpheus VB How-To 1 August 13th, 2003 09:14 AM
Select Case andy24 Classic ASP Databases 5 July 25th, 2003 07:52 AM
Select Case ziwez0 .NET Web Services 8 July 11th, 2003 02:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.