invalid XML identifier as required by FOR XML

 The weirdest error I got today was this : 

  •  Column name 'DATA()' contains an invalid XML identifier as required by FOR XML; '('(0x0028) is the first character at fault.

This was happening when I was trying to concatenate rows from a column into a single row like this :

   1:  
   2: REPLACE(
   4: (
   6: SELECT [Name] as [DATA()]
   7:   
   8:   FROM ContactPerson 
   9:  
  10:    WHERE ClientId = dbo.Client.ClientId
  12:    
  13: FOR XML PATH ('') ), ' ', ',') as AllPersonsNames

 I eventually found on a web site the answer : it shouldn't be DATA() it should be data() Surprised

Tags: ,

Insert generator for MSSQL tables

Having inserted some data in an MSSQL database table, I wanted an easy way of creating an insert script for that specific table. And I don't want something fancy that will generate inserts for all my tables because most of the time the inserts I want generated are for tables that have lock-up data like : ProjetStatus or ProjectResolution. I certanly didn't want something like : sqlmanager - it does alot of stuff that I just didn't need.

My first instinct was : "I'll create a small application with the help of SMO that will ....."(slaps self arround the head). I realized this would take some time and it wouldn't be very usefull. What I really wanted was something done by someone else, something that just worked. 

A quick search on google revealed a cool stored procedure for MSSQL that would do exactly what I wanted and more, here it is: a procedure that would generate inserts for your data.

And the beauty of it is that it just worked. The script generates the procedure in the Master database so don't look for it in your database like I did :).

I also saved the file here, in case the original site won't respond at one point.

generate_inserts_mssql.txt (18.97 kb)

Tags: