if------then ----else in select statement

  • in temp1 mtd field ,some of the values r null

    if this is null

    i need to call another sp and get value

  • riya_dave (4/19/2012)


    in temp1 mtd field ,some of the values r null

    if this is null

    i need to call another sp and get value

    You are only pulling the account column from #temp1, nothing else. Look at your code for declaring the cursor c1. Look carefully at the select statement.

  • At least he's consistent. This is just as bad as his other post. 😀

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Mike01 (4/19/2012)


    At least he's consistent. This is just as bad as his other post. 😀

    LOL!!!!

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (4/19/2012)


    Mike01 (4/19/2012)


    At least he's consistent. This is just as bad as his other post. 😀

    LOL!!!!

    i dont know which is worse, the fact that he is consistently bad or that i am laughing right now.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • Now, now guys, play nice... clearly the man is in way over his head here!

    To the OP, judging by the responses you have posted here, I think you have one of two options to get your question answered:

    1. State clearly what it is you are trying to achieve and get any one of these professionals to give you a better approach/solution.

    2. If this is a learning exercise for you then I would suggest you post in the "Newbie" section stating

    your inexperience and someone would probably patiently hand hold you through to a solution.

  • Gleened some information from your latest post on your new thread and combined it here. Don't know if it is going to help or not.

    declare @Portfolio nvarchar(32)

    declare @mtd2 float

    DECLARE @qtd float

    declare @maxdate datetime

    select @maxdate = MAX(PeriodThrudate) from fPerformanceHistoryDetail(@i1)

    declare @ytd float

    declare c1 CURSOR FOR

    select account, mtd, qtd, ytd from #temp1

    open c1

    FETCH NEXT FROM c1 INTO @Portfolio, @mtd2, @qtd, @ytd

    WHILE @@FETCH_STATUS = 0

    begin

    --------month----------

    if(@mtd2 IS NULL )

    begin

    EXEC pPerformance

    @ReportData = @i3 out,

    @Portfolios = @Portfolios,

    @FromDate = @fromMTD,

    @ToDate = @ToDate

    select @mtd2 = IRR from APXUSER.fPerformance(@i3)

    select @mtd2 last1month

    end

    if(@ytd is null)

    begin

    EXEC pPerformance

    @ReportData = @ReportData3 out,

    @Portfolios = @Portfolio,

    @FromDate = @maxdate,

    @ToDate = @ToDate

    select @ytd = IRR from APXUSER.fPerformance(@i3)

    select @ytd as y21

    end

    ---------------------------------------------------------

    ------quatertodate---------------

    if(@qtd is null)

    begin

    declare @maxdate1 datetime

    select @maxdate1 = MAX(PeriodThrudate) from fPerformanceHistoryDetail(@i1)

    if(@maxdate1 >= @fromQTD)

    begin

    select @FromQTD = @maxdate1

    end

    -- -- select @maxdate

    EXEC pPerformance

    @ReportData = @i3 out,

    @Portfolios = @Portfolio,

    @FromDate = @fromQTD,

    @ToDate = @ToDate

    select @qtd = IRR from fPerformance(@i3)

    select @qtd as qtd1

    end

    INSERT INTO #temp2(account,MTDTWR,QTDTWR,YTDTWR) values(@Portfolio,@mtd2,@qtd,@ytd)

    fetch next from c1 into @Portfolio, @mtd2, @qtd, @ytd

    end

    close c1

    DEALLOCATE c1

  • riya_dave (4/17/2012)


    hi guys,

    i need help in my Stored procedure.

    select empname ,(select case when empno is null then

    begin

    declare salary

    declare @salary int

    declare c1 CURSOR FOR

    select distinct salary from dept

    open c1

    FETCH NEXT FROM c1

    INTO @salary

    WHILE @@FETCH_STATUS = 0

    ------some calculation---------------here i need to call another sp

    close c1;

    end

    else

    maxsalary

    END) AS salary

    from dept

    can we use like this in sql select , or do i need to use case statement,

    i dont have just 1 statement ,i have block of statement .so i think i cant use case

    any idea?

    You can drop the second Select before the Case and use it like below:

    select empname ,(case when empno is null then

    Edit: Nevermind!!...I just read the first opage and posted the reply. My bad. Didn't know there were 7 pages of replies.:-D

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

Viewing 8 posts - 61 through 67 (of 67 total)

You must be logged in to reply to this topic. Login to reply