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.
| Author |
Topic |
|
Trini
Starting Member
9 Posts |
Posted - 2008-08-05 : 20:07:37
|
| Hi all I would like to find out how to insert multiple records(Two Columns) from one table into another table with four columns.The records are filtered by Dept_ID and the two remaining columns will be populated via two variables. I am think something like the following but am not sure:(SQL 2005)DECLARE @L AS nvarcharDECLARE @P AS intSET @P=0.15SET @L='A'INSERT INTO dbo.Inv_DsSelect INum,StID,@L,@P FROM dbo.Disc WHERE Dept_ID=01 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-05 : 20:11:16
|
| That code looks good (except for the data type of @P since you can't put 0.15 in an int column), are you having an issue with it? The only thing to add to the script is the column list in the INSERT: INSERT INTO dbo.Inv_Ds (Column1, ..., Column4)Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
Trini
Starting Member
9 Posts |
Posted - 2008-08-05 : 20:25:18
|
| Thanks for your quick response. The error I am getting is as follows:"Conversion failed when converting the nvarchar value 'NONE' to data type int."I changed @L to nvarchar(2) and @P to real.These are the data types stored in the table. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Trini
Starting Member
9 Posts |
Posted - 2008-08-05 : 20:59:53
|
| dbo.Disc is a View from three tables.The fields for dbo.Inv_Ds follows:[StID] [nvarchar](10) NOT NULL,[INum] [nvarchar](20) NOT NULL,[L] [nvarchar](2) NOT NULL,[P] [real] NULL, |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-05 : 21:12:02
|
| You've got some issue in dbo.Disc that isn't allowing the data in. According to the error, you are trying to insert 'NONE' into a column that is defined as int. You can't insert non-integers into an int column.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
|
|
|