Color coat your code like below at: ASP.NET Resources
Validate GUID
  • First validate GUID is a guid.
  • Flag if GUID is invalid.
  • /* ValidateGUID.sql:  
          Ever have a GUID in a VARCHAR format and need to use it to query or update a table, but if the 
          data is invalid, you get the error:
          "Conversion failed when converting from a character string to uniqueidentifier."
    */
    DECLARE @AuthorizationCode as VARCHAR(64), @bValidAuth BIT
    SET @bValidAuth = 1
    SET @AuthorizationCode = 'D12FC09D-20A6-4D31-A14D-B5454EEDF453'
    
    BEGIN TRY
    	DECLARE @GUID uniqueidentifier
    	SET @GUID = CONVERT(uniqueidentifier, @AuthorizationCode)
    END TRY
    BEGIN CATCH
    	SET @bValidAuth = 0
    END CATCH
    
    SELECT @bValidAuth