September 14, 2014 at 12:11 am
Hello all,
Following is my table and its value
Employee table
empid(uniqueidentifier)
add96833-da07-44b1-ae66-0291c9c2fed8
d18b93b3-dd0f-45ad-813d-20928b46aede
I want to delete the row that has the id add96833-da07-44b1-ae66-0291c9c2fed8
How can i do that?
I wrote a sp and following is the code
ALTER PROCEDURE usp_emp_delete_details
@ipempguid uniqueidentifier,
as
Begin
delete from dbo.Employee where empid = @ipempguid
End
When i execute it , its giving me following error..
Incorrect syntax near '-'.
How can i make it work???
Thanks
Peter
September 14, 2014 at 12:40 am
Quick thought, when you pass the uniqueidentifier value to the procedure, you will have to pass it as a string, here is an example:
😎
USE tempdb;
GO
SET NOCOUNT ON
IF OBJECT_ID('dbo.SAMPLE_UNIQEID') IS NULL
BEGIN
CREATE TABLE dbo.SAMPLE_UNIQEID
(
SU_UNIQUEID UNIQUEIDENTIFIER NOT NULL
,SU_RID INT NOT NULL
);
INSERT INTO dbo.SAMPLE_UNIQEID (SU_RID,SU_UNIQUEID)
VALUES
(1 ,'798F6816-08B9-43EF-855B-627E6615BAB7')
,(2 ,'A2AD9BCF-BAF4-4124-A9A1-BB2F1BF4BCEF')
,(3 ,'7A397086-0A8D-4FEB-A1DE-1D62FCC0DE2A')
,(4 ,'3197FD4C-6A82-414D-99BE-3E977597E986')
,(5 ,'0B89ED39-AC4D-43E7-BC1D-300308ADEFCB')
,(6 ,'E90B0C0C-E368-4C7E-A208-40357D10624B')
,(7 ,'EE719442-5FB3-4BF5-95F4-85ABC62FAF8F')
,(8 ,'8BFF7505-B706-4986-B00C-437D21A80EB8')
,(9 ,'3039104D-3516-40A6-9324-AF801341809F')
,(10 ,'96AEE32E-2342-4F0D-82DF-EAC5539C227E');
END
DECLARE @UNIQUE_ID UNIQUEIDENTIFIER = 'A2AD9BCF-BAF4-4124-A9A1-BB2F1BF4BCEF';
SELECT
SU.SU_RID
,SU.SU_UNIQUEID
FROM dbo.SAMPLE_UNIQEID SU
WHERE SU.SU_UNIQUEID = @UNIQUE_ID
Results
SU_RID SU_UNIQUEID
----------- ------------------------------------
2 A2AD9BCF-BAF4-4124-A9A1-BB2F1BF4BCEF
Edit: typo
September 14, 2014 at 11:15 am
peterausger (9/14/2014)
When i execute it , its giving me following error..Incorrect syntax near '-'.
How can i make it work???
There's nothing wrong with your procedure, you just have to put the uniqueidentifier in quotes when you call it
EXEC usp_emp_delete_details 'add96833-da07-44b1-ae66-0291c9c2fed8'
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 14, 2014 at 2:24 pm
GilaMonster (9/14/2014)
peterausger (9/14/2014)
When i execute it , its giving me following error..Incorrect syntax near '-'.
How can i make it work???
There's nothing wrong with your procedure, you just have to put the uniqueidentifier in quotes when you call it
EXEC usp_emp_delete_details 'add96833-da07-44b1-ae66-0291c9c2fed8'
Or in a SQL variable.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply