Convert VChar(100) to GUID in a stored proc

  • I have a classic asp page that is accessed via different pages. In some situations the:

    Request.QueryString("Contract_ID") is a vchar(100) and sometimes is coming a GUID.

    When it is vchar(100) and this value is passed to a stored proc, I want to check the data type and if it is not a uniqueidentifier type, I want to convert it to a uniqueidentifier type.

    How can I do that?

  • Faye Fouladi (8/31/2009)


    I have a classic asp page that is accessed via different pages. In some situations the:

    Request.QueryString("Contract_ID") is a vchar(100) and sometimes is coming a GUID.

    When it is vchar(100) and this value is passed to a stored proc, I want to check the data type and if it is not a uniqueidentifier type, I want to convert it to a uniqueidentifier type.

    How can I do that?

    if i pass an any string not exactly 36 chars, a space, a zero or any integer, or "lowell" as the contract_id, it is simply NOT possible, to convert it to a uniqueidentifier in SQL

    you'd be best of testing this on the asp page, rather than trying to get SQL to cast/convert it to uniqueidentifier; plus if it did NOT cast to unique identifer, what do you do? generate a new one?

    a unique identifier is 36 chars, does not have an ascii letter greater F(A-F, no lower cases, right?)

    and has hyphens in specific places. if all those items are true, you can convert it, but if it is not, there is no built in way to convert it to uniqueidentifier...

    can you explain your real requirement better? you might be thinking one way, but the way to tackle the prblem is another way.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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