Question : Conversion failed when converting from a character string to uniqueidentifier.

I have a question with one of my sp, could you guys please help me?

create table testid (ud uniqueidentifier, id varchar(30))

create procedure testtsp
@id varchar(50),
@input varchar(50)
as
begin
update testid set id = @id where ud = @input;
end

exec testtsp '5ade3ad2-5d1e-4febbb-bfb6-1def2a11eebdd',12

I am getting casting error for uniqueidentifier. My application will pass input parameters as varchar only.

Answer : Conversion failed when converting from a character string to uniqueidentifier.

Two mistakes:

1. Parameters uniqueidentifier and varchar are not passed correctly in the procedure.
2. value for Uniqueidentifier passed ie., '5ade3ad2-5d1e-4febbb-bfb6-1def2a11eebdd' is not a valid uniqueidentifier and the correct one was '5ade3ad2-5d1e-4feb-bfb6-1def2a11eebdd'

Fixed code below:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
use test
create table testid (ud uniqueidentifier, id varchar(30))

alter  procedure testtsp
@id varchar(30),
@input varchar(50)
as
begin
update testid set id = @id where ud = @input;
end

exec testtsp '12', '5ade3ad2-5d1e-4feb-bfb6-1def2a11eebdd'
Random Solutions  
 
programming4us programming4us