3

This seems really trivial, but for the life of me I cannot understand why this is not working. Any ideas would be great!

USE [ACCTQA]
GO

INSERT INTO [dbo].[glacct]
           ([Company]
           ,[Account]
           ,[Description])
     VALUES
 ('E096','191802','INVESTMENT IN SUBS')
,('E096','320007','COMMON STOCK')
,('E096','330013','SURPLUS')
,('E096','340003','RETAINED EARNINGS')
,('E096','690876','LIAB & CASUALTY INS')
,('E096','710000','BONDS - AGENCY BILL')
,('E096','710001','COMM. P&C - AGENCY BILL')
,('E096','710002','EMPL BENEFITS-AGENCY BILL')

ERROR MSG:

Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ','.
7
  • 1
    Any error message would be great Commented Feb 10, 2016 at 13:41
  • 1
    What is the error message? Commented Feb 10, 2016 at 13:42
  • 2
    Which version of SQL Server you are using? It works for SQL Server 2008 and above sqlfiddle.com/#!3/fd272 Commented Feb 10, 2016 at 13:42
  • if you use SQL Server CE, than it doesn't support bulk insert as I know Commented Feb 10, 2016 at 13:43
  • 1
    The database is on SQL 2005. All columns are char. Commented Feb 10, 2016 at 13:52

3 Answers 3

1

Try this

USE [ACCTQA]
GO

INSERT INTO [dbo].[glacct]
           ([Company]
           ,[Account]
           ,[Description])
SELECT * FROM (   
SELECT 'E096','191802','INVESTMENT IN SUBS' UNION ALL
SELECT 'E096','320007','COMMON STOCK' UNION ALL
SELECT 'E096','330013','SURPLUS' UNION ALL
SELECT 'E096','340003','RETAINED EARNINGS'
.....)

I'm guessing your version is not accepting multiple values like this, so you have to use a select statement(INSERT FROM SELECT) to make it work.

Sign up to request clarification or add additional context in comments.

Comments

1

Your query won't work if you are using SQL Server 2005 or below. On those version you have to try like

INSERT INTO glacct
  ([Company],[Account],[Description]) 
SELECT 'E096','191802','INVESTMENT IN SUBS'
UNION ALL
SELECT 'E096','320007','COMMON STOCK'
UNION ALL
SELECT 'E096','330013','SURPLUS' 

Your query will work on SQL Server 2008 and above,.

SQL FIDDLE DEMO

2 Comments

That's my answer.. are you serious?
This only inserted the first 366 rows. No errors, states that query executed successfully?
0

It did the trick...

CREATE TABLE #glacct (Company VARCHAR(100),
                        Account INT,
                    Description VARCHAR(200))

INSERT INTO [dbo].[#glacct]
           ([Company],
            [Account],
            [Description])
     VALUES
('E096','191802','INVESTMENT IN SUBS'),
('E096','320007','COMMON STOCK'),
('E096','330013','SURPLUS'),
('E096','340003','RETAINED EARNINGS'),
('E096','690876','LIAB & CASUALTY INS'),
('E096','710000','BONDS - AGENCY BILL'),
('E096','710001','COMM. P&C - AGENCY BILL'),
('E096','710002','EMPL BENEFITS-AGENCY BILL')

PS: Done with SQLServer 2014 ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.