[T-SQL] Line 21: Incorrect syntax near '+'.

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • Snake
  • Registratie: Juli 2005
  • Laatst online: 07-03-2024

Snake

Los Angeles, CA, USA

Topicstarter
Ik zit hier al uren te pielen op hetzelfde code.

Ik probeer mijn SQL tabellen weg te schrijven naar een xls bestand zodat ik een 'reportje' krijg.

Mijn TSQL is hetvolgende:

SQL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
DECLARE @table_name NVARCHAR(50)
DECLARE @cmd NVARCHAR(255)
DECLARE tableList CURSOR
FOR SELECT table_name FROM INFORMATION_SCHEMA.TABLES

OPEN tableList
FETCH NEXT FROM tableList INTO @table_name

WHILE @@FETCH_STATUS = 0
      BEGIN
            INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=d:\' + @table_name + '.xls', 'SELECT * FROM [Sheet1$]')

            SELECT column_name, data_type
            FROM INFORMATION_SCHEMA.columns
            WHERE table_name = @table_name

        FETCH NEXT FROM tableList INTO @table_name
      END
CLOSE tableList
DEALLOCATE tableList

Nu kan ik hier echt niet aan uit komen, ik heb al zitten Googlen op concatenaten van 2 strings in TSQL, maar volgens de documentatie doe ik het goed. Er is 1 link op Google waarin dezeflde error wordt gespecifieerd, maar helaas geeft die een 404. Kan iemand mij helpen? :$

Going for adventure, lots of sun and a convertible! | GMT-8


Acties:
  • 0 Henk 'm!

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Mag je in je OPENROWSET wel een variabele assignment doen? Als ik die concatenate weghaal, dan werkt 't perfect. Zelfs een nieuwe variabele declaren die je vantevoren set, wordt niet geaccepteerd (MS-SQL that is)

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


Acties:
  • 0 Henk 'm!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

Je moet die \ escapen. Dat zal dus
SQL:
11
            INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=d:\\' + @table_name + '.xls', 'SELECT * FROM [Sheet1$]')

worden. Zoals onze syntax highlighter ook al heel mooi aangeeft. ;)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

  • Snake
  • Registratie: Juli 2005
  • Laatst online: 07-03-2024

Snake

Los Angeles, CA, USA

Topicstarter
NMe schreef op vrijdag 07 augustus 2009 @ 13:58:
Je moet die \ escapen. Dat zal dus
SQL:
11
            INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=d:\\' + @table_name + '.xls', 'SELECT * FROM [Sheet1$]')

worden. Zoals onze syntax highlighter ook al heel mooi aangeeft. ;)
Njet that doesn't do the trick. Zelfde error.

Ik denk dat BtM909 gelijk heeft.

Going for adventure, lots of sun and a convertible! | GMT-8


Acties:
  • 0 Henk 'm!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

Klopt inderdaad. Hier staat een mogelijke oplossing.

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

NMe schreef op vrijdag 07 augustus 2009 @ 13:58:
Je moet die \ escapen. Dat zal dus
SQL:
11
            INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=d:\\' + @table_name + '.xls', 'SELECT * FROM [Sheet1$]')

worden. Zoals onze syntax highlighter ook al heel mooi aangeeft. ;)
Dat was 't eerste waar ik aan dacht (dat kan wellicht sowieso een probleem opleveren), maar MS-SQL lijkt dat gewoon te slikken.

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.

Pagina: 1