Dynamic SQL ? Help me

  • Hi all.

    Can someone help me with the following. I need to try and reduce the number of lines purely for a future maintenance point.

    I am using SPs to populate Treeviews in my app. I need one stored proc per level. each level may contain data from different tables depending on the parent level selected. So in my stored procs I am doing the following

    CREATE PROCEDURE [dbo].[prc599TextBankTreeViewLevel2]

    (@intParentID int, @intID int)

    AS

    If @intParentID = 1

      Select   A.name as something1,

                 A.age as something2,

                 A.desc as something3

      From table1 A  Where A.id = @id

    Else If @intParentID = 2

      Select   A.type as something1,

                 A.length as something2,

                 A.dec as something3

      From table2 A  Where A.name = @id

    Else

      Select   A.location as something1,

                 A.district as something2,

                 A.amount as something3

      From table1 A  Where A.id = @id

    I have only included a small sample here, but the if statement could have 20 plus clauses. I would like to try and reduce this if possible but only if it won't impact on the perfomance. Will the above run slowly?

    Thanks for any help

    CCB

     

  • Hi ,this link may be help you, is a solution of Fernando Guerrero he's a SQL SERVER guru

    http://groups.google.com.co/groups?hl=es&lr=lang_es|lang_en&ie=UTF-8&oe=UTF-8&selm=ezvdgGcfBHA.1448%40tkmsftngp02&rnum=3

    Jose Nadim

    PD.. Sorry for my english ,i'm speak spanish

     

Viewing 2 posts - 1 through 1 (of 1 total)

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