March 11, 2013 at 3:49 am
I want to combine this select statement and a variable(@EndUserDel) to get result.how can i do that?
declare @EndUserDel nvarchar(20)
select * FROM [dbo].[Service]
i want this way select *,@EndUserDel FROM [dbo].[Service]
how can i do that
March 11, 2013 at 4:11 am
vahid.arr (3/11/2013)
I want to combine this select statement and a variable(@EndUserDel) to get result.how can i do that?
declare @EndUserDel nvarchar(20)
select * FROM [dbo].[Service]
i want this way select *,@EndUserDel FROM [dbo].[Service]
how can i do that
So, just do what you have written.
select *, @EndUserDel FROM [dbo].[Service]
It is a valid T-SQL statement!
March 11, 2013 at 2:03 pm
Its worth noting that, if you do not assign a value to @EndUserDel it will return NULL value. See my comments in the code below
IF OBJECT_ID('tempdb..#service') IS NOT NULL
DROP TABLE #service;
CREATE TABLE #service (x varchar(10));
INSERT INTO #service SELECT 'abc' UNION ALL SELECT 'xyz';
DECLARE @EndUserDel AS varchar(10);
-- No value has been set for @EndUserDel so expect only NULLS for EndUserDel
-- Note the resultset:
SELECT *, @EndUserDel AS EndUserDel FROM #service
-- setting value for EndUserDel
SET @EndUserDel='Bob';
--Now look at the resultset:
SELECT *, @EndUserDel AS EndUserDel FROM #service
DROP TABLE #service;
GO
-- Itzik Ben-Gan 2001
March 12, 2013 at 10:55 am
vahid.arr (3/11/2013)
I want to combine this select statement and a variable(@EndUserDel) to get result.how can i do that?
declare @EndUserDel nvarchar(20)
select * FROM [dbo].[Service]
i want this way select *,@EndUserDel FROM [dbo].[Service]
how can i do that
If you're trying to put something into the variable, you'll need to assign its value in the select statement.
declare @EndUserDel nvarchar(20);
select @EndUserDel=<FieldName> from dbo.Service;
The nvarchar variable is scalar, so you'll want to put some kind of filter on the query so it only returns one record too. Not sure if that's what you were trying to accomplish, but maybe this helps.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply