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 |
|
DueyDooDah
Starting Member
3 Posts |
Posted - 2011-08-16 : 14:48:37
|
| I am attempting to access a table variable in the code below. in the last INSERT statement, I recive an error indicating the parameter(s) need to be scalar. Can someone point me in the right direction to accomplish what I am trying to to (access the columns of the loaded table variable and insert the data into another table [Computer]) Use [PC Inventory] go IF OBJECT_ID ('UpdateTables','P') IS NOT NULL DROP PROCEDURE UpdateTables GO CREATE PROCEDURE UpdateTables AS BEGIN DECLARE @tbl TABLE ( [PC Name] nvarchar (255), FirstName nvarchar (255), LastName nvarchar (255), [Office Code] nvarchar (255), Location nvarchar (255), [Use] nvarchar (255), OS nvarchar (255), Chip nvarchar (255), [RAM (MB)] nvarchar (255), [Hard drive size] nvarchar (255), [System] nvarchar (255), [S/N or Svc Tag] nvarchar (255), [Model number] nvarchar (255), [Type (L or D)] nvarchar (255), [Other Cpmponents] nvarchar (255), Device nvarchar (255), [Dock S/N] nvarchar (255), Monitor nvarchar (255), [Monitor S/N] nvarchar (255), Warranty nvarchar (255), Acquired DATETIME, [Warranty Expires] DATETIME, Retired DATETIME, Vendor nvarchar (255), [Budget Center] nvarchar (255), [Total Price] MONEY, Notes nvarchar (255), [XP OS Product Key XP] nvarchar (255), [License info] nvarchar (255), [Donated To] nvarchar (255), [Date donated] DATETIME, [Item Type] nvarchar (255), [Path] nvarchar (255) ) INSERT INTO @tbl SELECT * FROM temptable WHERE [S/N or Svc Tag] NOT IN (SELECT SerialNumber FROM Computer) INSERT INTO Computer ( ComputerName, SerialNumber, PurchaseDate ) VALUES ( @tbl.[PC Name], @tbl.[S/N or Svc Tag], @tbl.[Acquired] ) END |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
DueyDooDah
Starting Member
3 Posts |
Posted - 2011-08-16 : 15:03:36
|
| Yes, I should have explained a bit on that. My intention is to do just as you say. But, as I am new to this I wanted to walk through how data moves with the debugger and watch how it all works. Also, because I have many related tables to update using this information, I wanted to do a step-by=-step examination of each column transfer to ensure I don't miss anything, especially when I must update the relational data. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
DueyDooDah
Starting Member
3 Posts |
Posted - 2011-08-16 : 15:37:17
|
| Excellent! Thank you very much. I guess I still need more study on the nuances of the SELECT statement. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|