Preguntas etiquetadas con sql-server-2008

250
SQL Server SELECT INTO @variable?

Tengo el siguiente código en uno de mis Sql (2008) Stored Procs que se ejecuta perfectamente: CREATE PROCEDURE [dbo].[Item_AddItem] @CustomerId uniqueidentifier, @Description nvarchar(100), @Type int, @Username nvarchar(100), AS BEGIN DECLARE @TopRelatedItemId uniqueidentifier; SET...

248
Restricción única en múltiples columnas

CREATE TABLE [dbo].[user]( [userID] [int] IDENTITY(1,1) NOT NULL, [fcode] [int] NULL, [scode] [int] NULL, [dcode] [int] NULL, [name] [nvarchar](50) NULL, [address] [nvarchar](50) NULL, CONSTRAINT [PK_user_1] PRIMARY KEY CLUSTERED ( [userID] ASC ) ) ON [PRIMARY] GO ¿Cómo agrego una...

243
Insertar SQL Server si no existe

Quiero insertar datos en mi tabla, pero insertar solo datos que no existen en mi base de datos. Aquí está mi código: ALTER PROCEDURE [dbo].[EmailsRecebidosInsert] (@_DE nvarchar(50), @_ASSUNTO nvarchar(50), @_DATA nvarchar(30) ) AS BEGIN INSERT INTO EmailsRecebidos (De, Assunto, Data) VALUES...

199
¿Puedo usar múltiples "con"?

Solo por ejemplo: With DependencedIncidents AS ( SELECT INC.[RecTime],INC.[SQL] AS [str] FROM ( SELECT A.[RecTime] As [RecTime],X.[SQL] As [SQL] FROM [EventView] AS A CROSS JOIN [Incident] AS X WHERE patindex('%' + A.[Col] + '%', X.[SQL]) > 0 ) AS INC ) With lalala AS ( SELECT...