Help with trimming a variable/parameter...

  • I have an ASPX page that references a stored procedure. That page strings the ID that I need to pass into the stored procedure. In my stored procedure, that ID gets passed into the where clause as:

    DonationID = @DonationID

    The problem is that the page passes the id using a { at the beginning and a } at the end. I need to trim these off of the ID. My idea was that I could trim this off in my SP on my @DonationID. Is there a way to do this, or am I taking the wrong approach. Thanks guys.

  • I'd strip it in .NET.

    You can do it easy enough in SQL too. Replace(Replace(@DonationID, '{', ''), '}', '')

  • It sounds like your application my be passing a GUID. If that is the case, just cast it to a uniqueidentifier in SQL and it will remove the curly braces. Here is an example.

    Declare @DonationID varchar(50)

    Set @DonationID = '{' + cast(NewID() as varchar(50)) + '}'

    Select @DonationID

    Select Cast(@DonationID as uniqueidentifier)

  • Jack Corbett (12/3/2008)


    I'd strip it in .NET.

    You can do it easy enough in SQL too. Replace(Replace(@DonationID, '{', ''), '}', '')

    Worked like a charm. I didnt think I could do a replace on a variable. This is awesome and will help in the future. Thanks!

Viewing 4 posts - 1 through 3 (of 3 total)

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