Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: UniqueIdentifier variable for select

    What am i doing wrong here?


    DECLARE @ApplicationId uniqueidentifier
    DECLARE @UserId uniqueidentifier
    DECLARE @UserName nvarchar(256)

    SELECT @ApplicationID='D346B556-0975-4FCA-84F4-4820759D3D05',
    @UserId='0798F1DD-9690-48DD-B538-AE3C84A1A3E5'

    SELECT dbo.aspnet_Users.UserName
    FROM dbo.aspnet_Users
    WHERE dbo.aspnet_Users.UserName =CAST(@UserId as uniqueidentifier)
    AND dbo.aspnet_Users.ApplicationId=CAST(@ApplicationId as uniqueidentifier)

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Try
    Code:
    SELECT @ApplicationID='{D346B556-0975-4FCA-84F4-4820759D3D05}',
    @UserId='{0798F1DD-9690-48DD-B538-AE3C84A1A3E5}'
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Oct 2003
    Posts
    233
    I still get the same error :
    "Msg 8169, Level 16, State 2, Line 8
    Conversion failed when converting from a character string to uniqueidentifier."

    I tried with & without the cast

  4. #4
    Join Date
    Oct 2003
    Posts
    233
    Im a bone head, i had userName=@UserId it should have been Userid=@User id...


    DECLARE @ApplicationId nvarchar(256)
    DECLARE @UserId nvarchar(256)
    DECLARE @UserName nvarchar(256)

    SELECT @ApplicationID='D346B556-0975-4FCA-84F4-4820759D3D05',
    @UserId='0798F1DD-9690-48DD-B538-AE3C84A1A3E5'

    SELECT dbo.aspnet_Users.UserName , dbo.aspnet_Users.ApplicationId , dbo.aspnet_Users.UserId
    FROM dbo.aspnet_Users
    WHERE dbo.aspnet_Users.Userid = @UserId
    AND dbo.aspnet_Users.ApplicationId= @ApplicationId

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •