0

I have this script:

DELETE FROM [Tags] WHERE Id = CONVERT(uniqueidentifier, '7373D1A0-CB6A-4207-87C4-AE2939FD20C0');
GO
INSERT INTO [Tags] VALUES (CONVERT(uniqueidentifier, '7373D1A0-CB6A-4207-87C4-AE2939FD20C0'), 'Business');
GO

I want to declare a @businessId constant to hold the result from my

CONVERT(uniqueidentifier, '7373D1A0-CB6A-4207-87C4-AE2939FD20C0') 

The end result should look cleaner:

DELETE FROM [Tags] WHERE Id = @businessId;
GO
INSERT INTO [Tags] VALUES (@businessId, 'Business');
GO

Is there a way to do this in SQL Server CE 4? If no, is there a way to do this in SQL Server?

Thank you for your help.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MoonLight
  • 37
  • 2
  • 4

1 Answers1

1

In T-SQL (SQL Server) you would write

Declare @businessId UniqueIdentifier;
set @businessId = '7373D1A0-CB6A-4207-87C4-AE2939FD20C0';

I would imagine that it is the same in SQL Server CE but I will confirm it;

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nathan Fisher
  • 7,961
  • 3
  • 47
  • 68
  • I get this error : Declare @businessId UniqueIdentifier There was an error parsing the query. [ Token line number = 14,Token line offset = 1,Token in error = Declare ]. Maybe SQL CE doesn't support the declaration of variables. – MoonLight Mar 06 '12 at 03:47
  • 1
    it seems that SQL Server Compact does not allow the declare statement. you can parameterise a sql command and add the parrameters via the .net SQLCECommand object. see http://stackoverflow.com/q/4056872/29467 – Nathan Fisher Mar 06 '12 at 04:17
  • Thanks, Just what i needed! (on mssql thou) – schmidiii Mar 14 '13 at 10:51