Re: 'select case' in stored procedure ?

From: Agnes (agnes_at_dynamictech.com.hk)
Date: 07/21/04


Date: Wed, 21 Jul 2004 15:32:38 +0800

I need to specified the column ??
infact, i got several column may be update (which depends on the case
parameter)
it seems wrong syntax if my code like this :-
update mytable
case @type
when 'A' then a = a + 1
when 'B' then b = b + 1
end

"Narayana Vyas Kondreddi" <answer_me@hotmail.com> 在郵件
news:u$7yJJvbEHA.2292@TK2MSFTNGP09.phx.gbl 中撰寫...
> Yes, something like this:
>
> UPDATE TableName
> SET ColumnName = CASE WHEN <Condition1> THEN <Value1> WHEN <Condition2>
THEN
> 'Value2' ELSE 'Value3' END
> WHERE <Some condition to select the rows>
> --
> Vyas, MVP (SQL Server)
> http://vyaskn.tripod.com/
>
>
> "Agnes" <agnes@dynamictech.com.hk> wrote in message
> news:%23EBiSjubEHA.1644@tk2msftngp13.phx.gbl...
> > How about update statment ?
> > After i select * from table, i need to update it at once.. but It
depends
> on
> > the condition,
> > Can update got the 'case' also ??
> >
> > "Agnes" <agnes@dynamictech.com.hk> 在郵件
> > news:eiIlaFubEHA.2812@tk2msftngp13.phx.gbl 中撰寫...
> > > I understand and try it later . Thanks
> > > this syntax seems quit useful. as i don't need to create several store
> > > procedure
> > > "Narayana Vyas Kondreddi" <answer_me@hotmail.com> 在郵件
> > > news:eXnTy4mbEHA.3596@tk2msftngp13.phx.gbl 中撰寫...
> > > > A quick example:
> > > >
> > > > SELECT EmpID, EmpName,
> > > > CASE Sex
> > > > WHEN 'm' THEN 'Male'
> > > > WHEN 'f' THEN 'Female'
> > > > ELSE 'Unspecified'
> > > > END AS 'Sex'
> > > > FROM Employees
> > > >
> > > > --
> > > > HTH,
> > > > Vyas, MVP (SQL Server)
> > > > http://vyaskn.tripod.com/
> > > > Is .NET important for a database professional?
> > > > http://vyaskn.tripod.com/poll.htm
> > > >
> > > >
> > > > "Agnes" <agnes@dynamictech.com.hk> wrote in message
> > > > news:un8wE0mbEHA.3096@tk2msftngp13.phx.gbl...
> > > > Can I use select case in "stored procedure ???
> > > > If yes, can someone be kind to give me a sample ??
> > > > Thanks
> > > > From SQL-newbie
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: INSERT statement using variables
    ... "sm" schrieb: ... > Can anybody give me the syntax to insert a record into ... > SQL server through VB code using variables? ... Herfried K. Wagner [MVP] ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Is Access SQL FROM Clause different from MS SQL Server SQL?
    ... The specific question about tbl4 in this query can be answered. ... syntax and functionality of this is the same as in SQL Server. ... CROSS JOIN in SQL Server's Books Online, ... The syntax of representing a CROSS JOIN by just a comma may be less ...
    (microsoft.public.access.queries)
  • RE: Access project vs. Access db
    ... Because the syntax you are using is asking the database engine to compare ... Jet won't warn you of this logic error, but SQL Server does. ... Where can I get general/ongoing help with what may be a host of these ...
    (microsoft.public.access.modulesdaovba)
  • Re: Problem Maintaing Excel Format after Mail Merge
    ... "macropod" wrote: ... Thanks for your sample syntax. ... Now, my test condition require IF Field 2=D, then Field 1 format must be ... Graham Mayor - Word MVP ...
    (microsoft.public.word.mailmerge.fields)
  • Re: HELP! UPDATE syntax that work in sql server and access vba
    ... When you are working with Access ODBC linked tables, you must use the JET ... You should ask in a newsgroup about queries under Access how to ... In sql server I use syntax as follow: ... I also tried the following syntax in access query: ...
    (microsoft.public.access.adp.sqlserver)