Is Uniqueidentifier(String)

  • Hi,

    Is there any way I can check if a string being passed from an ASP (VbScript) page conforms to GUID conventions before I attempt to do a table lookup using it?

    I have checked my documentation for T-Sql and VbScript, and while I can use Isdate, Isnumeric etc, I can't find anything like IsUniqueIdentifier.

    Many Thanks in Advance

    Cp

  • This was removed by the editor as SPAM

  • Couldn't you simply do this?

     

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[isuniqueidentifier]') and xtype in (N'FN', N'IF', N'TF'))

    drop function [dbo].[isuniqueidentifier]

    GO

    CREATE FUNCTION dbo.isuniqueidentifier (@unique varchar(100)) 

    RETURNS bit AS 

    BEGIN

    declare @return bit

    set @return = 0

    if right(left(@unique,9),1)+right(left(@unique,14),1)+right(left(@unique,19),1)+right(left(@unique,24),1) = '----'

    if len(@unique) = 36

    set @return = 1

    return @return

    END

    GO

    select dbo.isuniqueidentifier(newid())

    select dbo.isuniqueidentifier('49411F4D-088F-44E4-8526-B637D94D0204')

    select dbo.isuniqueidentifier('49411F4D-088F-44E4-85261B637D94D0204')

    select dbo.isuniqueidentifier('not unique')

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[isuniqueidentifier]') and xtype in (N'FN', N'IF', N'TF'))

    drop function [dbo].[isuniqueidentifier]

    GO

     

  • Thankyou William,

    I will try to understand what what you have written and test it. I am not sure about the "Simply" though, it looks quite complex to me.

    I am currently doing a number of checks (length, enclosed in {}, "-" in the right locations, characters are in the right Ascii range etc) in VbScript. However, as it has to do a Mid(char,x) by Mid(char,x) scan of the string it looks quite cpu intensive and not the sort of thing I want to put on the production server.

    Many Thanks

    Conway

  • Hi,

    I have had a chance to try this out and see what it is doing. It does much the same as my current VbScript, insofar as it checks for the length etc. However, it does not check to ensure the character blocks are Hexadecimal.

    I am going to investigate using the Error object to see if I can capture the error generated when the Automatic "Cast" takes place.

    Ho hum, back to the grindstone.

    Regards

    Conway

  • William,

    I do understand that you are checking if there are - at the certain positions. Please, explain why are you using right(left(@unique,9),1) for example, not substring(@unique,9,1)  unless it is just a matter of preference.

    Yelena

    Regards,Yelena Varsha

Viewing 6 posts - 1 through 5 (of 5 total)

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