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
 temp tables

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-03-11 : 07:23:55
hi
trying to get my info into a temp table. not sure if im doing it right.
DECLARE @FirstTable TABLE (RandomInteger nvarchar)
BEGIN
INSERT INTO @FirstTable
SELECT * FROM generic.DailyPrice
inner
join generic.Simulation
on generic.DailyPrice.ISIN =generic.Simulation.ISIN
where Date=
(SELECT MAX(Date) FROM generic.DailyPrice)
end
go

getting this error
Column name or number of supplied values does not match table definition
any ideas

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-11 : 07:28:03
[code]
DECLARE @FirstTable TABLE (RandomInteger nvarchar)
BEGIN
INSERT INTO @FirstTable
SELECT column corresponding to randominteger field
FROM generic.DailyPrice
inner
join generic.Simulation
on generic.DailyPrice.ISIN =generic.Simulation.ISIN
where Date=
(SELECT MAX(Date) FROM generic.DailyPrice)
end
go
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-03-11 : 07:30:42
i dont have an actually table for it. i want to do it without creating a table. i no there is a way to d0 this right
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-03-11 : 09:32:45
have it like this now
DECLARE @FirstTable TABLE
(
Fk_fund int,
Date datetime,
isin nvarchar,
Fundname ntext,
ShareCurrency nvarchar,
Pricepershare numeric,
exchanegRate numeric,
FirstSimulation nvarchar,
SecondSimulation nvarchar,
ThirdSimulation nvarchar
)




INSERT INTO @FirstTable (Fk_fund, Date,isin,Fundname,ShareCurrency, Pricepershare,
exchanegRate,FirstSimulation,SecondSimulation,ThirdSimulation)
SELECT dp.Fk_fund ,
dp.Date ,
dp.isin ,
dp.Fundname,
dp.ShareCurrency ,
dp. Pricepershare ,
dp. exchanegRate ,
s.FirstSimulation ,
s.SecondSimulation ,
s.ThirdSimulation
FROM generic.DailyPrice dp
inner
join generic.Simulation s
on dp.ISIN =s.ISIN
where Date=
(SELECT MAX(Date) FROM generic.DailyPrice)


getting this error
Msg 8152, Level 16, State 13, Line 21
String or binary data would be truncated.
The statement has been terminated.
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2013-03-11 : 10:11:49
got this working
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-11 : 12:15:56
Make sure your varchar fields have enough length to hold the incoming data to avoid this error. Recommended approach is to keep the length same as that of source field from which you insert

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -