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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Error Message

Author  Topic 

velvettiger
Posting Yak Master

115 Posts

Posted - 2008-05-19 : 11:41:04
Hi again,

I am receiving an error message in my code stating that the Column name or number of supplied values does not match table definition.

1)Now this query works without the Insert statement but when i try to insert the result in to a new table it doesn't work

2)Prior to me adding in a new column called 'brand', the code worked when i ran it to see the results and it also worked when i tried to insert it into a new table it also worked.

3)Since this was a new column, I also included the new column name in design view along with its data type and length etc

Any help would be greatly appreciated and I am totally at a lost.

The error I am getting is this

Server: Msg 213, Level 16, State 5, Line 6
Insert Error: Column name or number of supplied values does not match table definition.


Below is the code



SELECT SCLData_Unique_Sale_Summary.*,
SCLData_Unique_Product_Summary.ProductBarcode,
SCLData_Unique_Product_Summary.ProductDescription,
SCLData_Unique_Product_Summary.ActivePrice,
SCLData_Unique_Product_Summary.TotalProductQuantity,
SCLData_Unique_Product_Summary.TotalProductSalePrice,
SCLData_Unique_Product_Summary.DepartmentDescription,
SCLData_Unique_Product_Summary.SubDeptDescription,
SCLData_Unique_Product_Summary.Brand,
CASE DATEPART( dw, AccountingDate )
WHEN '1' THEN 'SUNDAY'
WHEN '2' THEN 'MONDAY'
WHEN '3' THEN 'TUESDAY'
WHEN '4' THEN 'WEDNESDAY'
WHEN '5' THEN 'THURSDAY'
WHEN '6' THEN 'FRIDAY'
WHEN '7' THEN 'SATURDAY'
END AS AccountDateWeekDay,
CASE DATEPART( m, AccountingDate )
WHEN '1' THEN 'JAN'
WHEN '2' THEN 'FEB'
WHEN '3' THEN 'MAR'
WHEN '4' THEN 'APR'
WHEN '5' THEN 'MAY'
WHEN '6' THEN 'JUN'
WHEN '7' THEN 'JUL'
WHEN '8' THEN 'AUG'
WHEN '9' THEN 'SEP'
WHEN '10' THEN 'OCT'
WHEN '11' THEN 'NOV'
WHEN '12' THEN 'DEC'
END AS AccountDateMonth,
CASE SCLData_Unique_Sale_Summary.StoreId
WHEN '105' THEN '3001'
WHEN '101' THEN '3024'
WHEN '112' THEN '3025'
WHEN '103' THEN '3003'
WHEN '102' THEN '3002'
END AS SubsidiaryId
FROM (
SELECT
StoreId,
LaneNumber,
InvoiceNumber,
TransactionNumber,
ProductBarcode,
MAX( ProductDescription ) ProductDescription,
MAX( ActivePrice ) ActivePrice,
CEILING( SUM( CONVERT( DECIMAL(10,2), Quantity ) ) ) TotalProductQuantity,
SUM( CONVERT( DECIMAL(10,2), DollarAmount ) ) TotalProductSalePrice,
MAX( DepartmentDescription ) DepartmentDescription,
MAX( SubDeptDescription ) SubDeptDescription
,Brand
FROM (
SELECT DISTINCT
F1068 AS TransactionType,
F254 AS AccountingDate,
F253 AS SystemDate,
F1056 AS StoreId,
F1057 AS LaneNumber,
F1035 AS TransactionStartTime,
F1036 AS TransactionEndTime,
F1032 AS TransactionNumber ,
F1764 AS InvoiceNumber,
F1185 AS OperatorNumber,
F1126 AS OperatorCode,
F1127 AS OperatorName,
F1148 AS MagnaNumberShort,
F01 AS ProductBarcode,
F02 AS ProductDescription,
F04 AS SubDepartmentCode,
F03 AS DepartmentCode,
F97 AS TaxableFlag,
F113 AS ActivePriceDescription,
F1101 AS ItemLineNumber,
F1007 AS ActivePrice,
F1006 AS ActiveQuantity,
F65 AS DollarAmount,
F64 AS Quantity,
F1263 AS Brand,
F238 AS DepartmentDescription,
F1022 AS SubDeptDescription,
F9999 AS XmlFile
FROM SCLData_tab
) AS SCLData_Unique_WorkTable
WHERE ISNUMERIC( DollarAmount ) = 1
AND ISNUMERIC( Quantity ) = 1
AND StoreId BETWEEN '101' AND '112'
GROUP BY StoreId, LaneNumber, InvoiceNumber, Brand, TransactionNumber, ProductBarcode
) AS SCLData_Unique_Product_Summary,
(
SELECT
StoreId,
LaneNumber,
InvoiceNumber,
TransactionNumber,
Brand,
MAX( MagnaNumberShort ) MagnaNumberShort,
MAX( TransactionType ) TransactionType,
MIN( AccountingDate ) AccountingDate,
MIN( TransactionStartTime ) TransactionStartTime,
MAX( TransactionEndTime ) TransactionEndTime,
CEILING( SUM( CONVERT( DECIMAL(10,2), Quantity ) ) ) TotalSaleQuantity,
SUM( CONVERT( DECIMAL(10,2), DollarAmount ) ) TotalSalePrice
FROM (
SELECT DISTINCT
F1068 AS TransactionType,
F254 AS AccountingDate,
F253 AS SystemDate,
F1056 AS StoreId,
F1057 AS LaneNumber,
F1035 AS TransactionStartTime,
F1036 AS TransactionEndTime,
F1032 AS TransactionNumber ,
F1764 AS InvoiceNumber,
F1185 AS OperatorNumber,
F1126 AS OperatorCode,
F1127 AS OperatorName,
F1148 AS MagnaNumberShort,
F01 AS ProductBarcode,
F02 AS ProductDescription,
F04 AS SubDepartmentCode,
F03 AS DepartmentCode,
F97 AS TaxableFlag,
F113 AS ActivePriceDescription,
F1101 AS ItemLineNumber,
F1007 AS ActivePrice,
F1006 AS ActiveQuantity,
F65 AS DollarAmount,
F64 AS Quantity,
F1263 AS Brand,
F238 AS DepartmentDescription,
F1022 AS SubDeptDescription,
F9999 AS XmlFile
FROM SCLData_tab
) AS SCLData_Unique_WorkTable
WHERE ISNUMERIC( DollarAmount ) = 1
AND ISNUMERIC( Quantity ) = 1
AND StoreId BETWEEN '101' AND '112'
GROUP BY StoreId, LaneNumber, InvoiceNumber, Brand,TransactionNumber
) AS SCLData_Unique_Sale_Summary
WHERE SCLData_Unique_Sale_Summary.StoreId = SCLData_Unique_Product_Summary.StoreId
AND SCLData_Unique_Sale_Summary.LaneNumber = SCLData_Unique_Product_Summary.LaneNumber
AND SCLData_Unique_Sale_Summary.InvoiceNumber = SCLData_Unique_Product_Summary.InvoiceNumber
AND SCLData_Unique_Sale_Summary.TransactionNumber = SCLData_Unique_Product_Summary.TransactionNumber


Thanks

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2008-05-19 : 12:25:00
OK, how about posting the table definition of the table that you're inserting into?

Also, did you add the new column to your receiving table too? Is it in the same position as the Query? Is it the same datatype as the Query?

An infinite universe is the ultimate cartesian product.
Go to Top of Page

velvettiger
Posting Yak Master

115 Posts

Posted - 2008-05-19 : 14:24:40
Hi again,

The below are the definitions of the table that the information is going into

StoreId varchar 25
LaneNumber varchar 25
InvoiceNumber varchar 25
TransactionNumber varchar 25
MagnaNumberShort varchar 25
TransactionType varhar 25
AccountingDate varchar 25
TransactionStartTime varchar 25
TransactionEndTime varchar 25
TotalSaleQuantity numeric 17
ProductBarcode varchar 25
ProductDescription varchar 50
Brand varchar 255
ActivePrice varchar 25
TotalProcductQuantity numeric 17
TotalProcductSalePrice numeric 17
DepartmentDescription varchar 25
SubDeptDescription varchar 25
AccountDtaeWeekDay varchar 9
AccountDateMonth varchar 3
SubsidiaryId varchar 4


Below are the definitions of the table I am taking the information from

F1068 varchar 25
F254 varchar 25
F253 varchar 25
F1056 varchar 25
F1057 varchar 25
F1035 varchar 25
F1036 varchar 25
F1032 varchar 25
F1764 varchar 25
F1185 varchar 25
F1126 varchar 25
F1127 varchar 25
F1148 varchar 25
F1155 varchar 25
F01 varchar 25
F02 varchar 50
F04 varchar 25
F03 varchar 25
F97 varchar 25
F113 varchar 25
F1101 varchar 25
F1007 varchar 25
F1006 varchar 25
F65 varchar 25
F64 varchar 25
F1263 varchar 25
F238 varchar 25
F1022 varchar 25
F9999 varchar 25
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-19 : 14:28:19
When you run your query (just the SELECT without the INSERT), does it return the correct number of columns (same as table to be inserted)? Are they in the correct order, meaning in the same order as the table to be inserted into?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-05-19 : 15:13:59
Insead of SELECT *, you should specify the column names. That might solve your problem.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 15:25:44
1) Number of GROUP BY columns and aggregated columns do not match the select list.
2) using both distinct and group by is unnecessary
3) all select is only using 1 base table. rewrite query for better performance.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -