Tuesday, March 27, 2012

Case Statement

hi,
my procedure is
create procedure ct_tpin(@.Start_Date datetime,@.End_Date datetime,@.Rpt_Name
varchar(50))
as
begin
case when @.Rpt_Name = 'TpinGenerated' then
select gr_tpin_flag_t.KEY1, gr_cust_m.Name,gr_tpin_flag_t.dateandtime FROM
gr_tpin_flag_t, gr_cust_m
WHERE (gr_tpin_flag_t.tpinflag = 'G') AND (gr_tpin_flag_t.key1 =
gr_cust_m.key1) and
(dateandtime between convert(datetime, @.Start_Date ,3)
and convert(datetime,@.End_Date,3)
end
end
its throwing error near case and end, pls give me a solution.
thanks
vanithaHi Vanitha,
What about
IF @.Rpt_Name = 'TpinGenerated' THEN
BEGIN
<YourCodeor Selectstatement)
END
HTH, Jens SUessmeyer.|||its the alternate method.
but i want to know how i can handle this in case statement
"Jens" wrote:

> Hi Vanitha,
>
> What about
> IF @.Rpt_Name = 'TpinGenerated' THEN
> BEGIN
> <YourCodeor Selectstatement)
> END
> HTH, Jens SUessmeyer.
>|||CASE is an expression, not a statement. You cannot use CASE the way you trie
d. Use IF instead.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"vanitha" <vanitha@.discussions.microsoft.com> wrote in message
news:18033B4C-6327-4E07-BD91-F5DC81DD5C32@.microsoft.com...
> hi,
> my procedure is
> create procedure ct_tpin(@.Start_Date datetime,@.End_Date datetime,@.Rpt_Name
> varchar(50))
> as
> begin
> case when @.Rpt_Name = 'TpinGenerated' then
> select gr_tpin_flag_t.KEY1, gr_cust_m.Name,gr_tpin_flag_t.dateandtime FROM
> gr_tpin_flag_t, gr_cust_m
> WHERE (gr_tpin_flag_t.tpinflag = 'G') AND (gr_tpin_flag_t.key1 =
> gr_cust_m.key1) and
> (dateandtime between convert(datetime, @.Start_Date ,3)
> and convert(datetime,@.End_Date,3)
> end
> end
> its throwing error near case and end, pls give me a solution.
> thanks
> vanitha|||There is no Case "Statement" in TSQL.
Case is an Expression that can be used as part of a query not a control flow
statement like in other languages.
Please read the syntax for it in BOL
"vanitha" <vanitha@.discussions.microsoft.com> wrote in message
news:449441A9-BDA1-43AD-B49E-866EE67EE89D@.microsoft.com...
> its the alternate method.
> but i want to know how i can handle this in case statement
> "Jens" wrote:
>sql

No comments:

Post a Comment