0

When I run my code, I keep getting an error

Incorrect syntax near the keyword 'CONVERT'

I've checked & rechecked and I can't get where the error is

INSERT INTO stock (ID, GOODSNAME, QUANTITY, PRICE, [DESCRIPTION], GOODSIMAGE, REGDATE) 
    SELECT 
        'STOCK-5', 'Pine by 150 Wipes', 120,600.00, 'To Clean Faeces', 
        BulkColumn 
    FROM 
        Openrowset (Bulk 'ImageDirectory\IMG_20180206_113030.jpg', Single_Blob) AS tb_picture, 
        CONVERT(date, '2011/11/11')
Dale K
  • 25,246
  • 15
  • 42
  • 71
Mr. Royal
  • 21
  • 8
  • 2
    Can you post the Stick table Schema? @Mr. Royal – Mark Kram Jan 20 '19 at 12:12
  • also, `CONVERT` had nuances, since your date is confusing enough, please check this [QA](https://stackoverflow.com/a/10304533/4648586). confusing enough: computer might unable distinguish the month and day apart. – Bagus Tesa Jan 20 '19 at 12:15
  • 1
    you have six columns in the insertion list but seven comma sepearted values in th select list. – Barbaros Özhan Jan 20 '19 at 12:24

3 Answers3

1

That expression belongs in the SELECT clause not the FROM clause:

INSERT INTO stock (ID, GOODSNAME, QUANTITY, PRICE, [DESCRIPTION], GOODSIMAGE, REGDATE) 
    SELECT 'STOCK-5', 'Pine by 150 Wipes', 120,600.00,
           'To Clean Faeces', BulkColumn, CONVERT(date,'2011/11/11')
    FROM Openrowset(Bulk 'ImageDirectory\IMG_20180206_113030.jpg', Single_Blob) tb_picture
Mr. Royal
  • 21
  • 8
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Here is your current query slightly better formatted

INSERT INTO stock (ID, GOODSNAME, QUANTITY, PRICE, [DESCRIPTION], GOODSIMAGE) 
SELECT 'STOCK-5','Pine by 150 Wipes', 120,600.00,'To Clean Faeces', BulkColumn
FROM Openrowset (Bulk 'ImageDirectory\IMG_20180206_113030.jpg', Single_Blob) as tb_picture
, CONVERT(date,'2011/11/11')

The "as tb_picture" in this query is a table alias, not a selection list alias. The FROM clause has passed, you cannot simply add another expression after that. It should probably go between "BulkColumn" and "FROM"

Gert-Jan
  • 327
  • 1
  • 9
0

Try below query:

INSERT INTO stock (
  ID, GOODSNAME, QUANTITY, PRICE, [DESCRIPTION], 
  GOODSIMAGE, REGDATE
) 
SELECT 
  'STOCK-5', 
  'Pine by 150 Wipes', 
  120, 
  600.00, 
  'To Clean Faeces', 
  BulkColumn, 
  Convert(date, '2011/11/11') 
FROM 
  Openrowset (
    Bulk 'ImageDirectory\IMG_20180206_113030.jpg', 
    Single_Blob
  ) as tb_picture
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
Mr. Royal
  • 21
  • 8