Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Server - Variable into table

Author  Topic 

delbar
Starting Member

5 Posts

Posted - 2009-11-26 : 04:02:33
I have a sproc that calls a procedure to retrieve information and the procedure has a variable @QTRYYYY. I have a parameter called @dateval that retrieves the @QTRYYYY from the procedure. I am new to this....

@DateVal as varchar (5)

Declare @people table
(NewPK int identity(1,1),
Org char(3) null,
License char(6) null,
@DateVal varchar (5) null
)

insert into @people
exec spGetRows @DateVal
end

;with CTEpeople
(org, License, Type,
Category, CategoryCount, @DateVal)
as (
Select
org,
license,
type,
@DateVal
from @people
etc....
this is not working. any suggestions on how to get the @DateVal into a table?

thanks,

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-11-26 : 04:18:16
quote:
Originally posted by delbar

I have a sproc that calls a procedure to retrieve information and the procedure has a variable @QTRYYYY. I have a parameter called @dateval that retrieves the @QTRYYYY from the procedure. I am new to this....

@DateVal as varchar (5)

Declare @people table
(NewPK int identity(1,1),
Org char(3) null,
License char(6) null,
@DateVal varchar (5) null
)

insert into @people
exec spGetRows @DateVal
end

;with CTEpeople
(org, License, Type,
Category, CategoryCount, @DateVal)--this is error
as (
Select
org,
license,
type,
@DateVal
from @people
etc....
this is not working. any suggestions on how to get the @DateVal into a table?

thanks,



try this..

Hi

You expect this...


DECLARE @DATEVAL INT

SET @DATEVAL = 1

DECLARE @PEOPLE TABLE (NEWPK INT IDENTITY(1,1), ORG CHAR(3) NULL)

INSERT INTO @PEOPLE
EXEC SPGETROWS @DATEVAL

SELECT * FROM @PEOPLE

;WITH CTEPEOPLE(NEWPK, ORG, DATEVAL)
AS
(
SELECT NEWPK, ORG, @DATEVAL
FROM @PEOPLE
)
SELECT * FROM CTEPEOPLE



CREATE proc spGetRows
@DateVal int
as
begin
if @DateVal = 1
select 'delbar'
end




-------------------------
R...
Go to Top of Page

delbar
Starting Member

5 Posts

Posted - 2009-11-26 : 04:46:53
Thank you it worked!

Go to Top of Page
   

- Advertisement -