Question : How to import mixed XML and data into a SQL Server table

Is there any way to import a data file in which some columns are normal data and some columns are XML.

For example, let's say this is the table:

CREATE TABLE [dbo].[Applicants](
      [AppID] [smallint] NOT NULL,
      [FName] [nvarchar](20) COLLATE Latin1_General_CS_AS NOT NULL,
      [LName] [nvarchar](40) COLLATE Latin1_General_CS_AS NOT NULL,
      [Resume] [xml] NULL
) ON [PRIMARY]

and let's say the data file looks something like this:

1,Sam,Sequel, '<Resume><Objective>Make lots of money</Objective></Resume>'
2,Sarah,Server,'<Resume><Objective>10 weeks vacation/year</Objective></Resume>'
3,Randy,Rocks,'<Resume><Objective>Not work 24/7</Objective></Resume>'

Without any CLR programing or use of SSIS - only SQL-related tools for SQL Server 2005 - what would the code be to get the data into the table so it looks like this when all is said and done:

AppID  FName  LName  Resume
1         Sam      Sequel   <Resume><Objective>Make lots of money</Objective></Resume>
2         Sarah   Server   <Resume><Objective>10 weeks vacation/year</Objective></Resume>  
3         Randy   Rocks   <Resume><Objective>Not work 24/7</Objective></Resume>

I've tried OPENROWSET and OPENXML and just couldn't seem to get it right... am sure I'm just missing something simple.  Please provide actual code in your answer.  Thanks in advance.

Answer : How to import mixed XML and data into a SQL Server table

You need to pass it through a temp table.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
CREATE TABLE #Applicants (
      [AppID] [smallint] NOT NULL,
      [FName] [nvarchar](20) COLLATE Latin1_General_CS_AS NOT NULL,
      [LName] [nvarchar](40) COLLATE Latin1_General_CS_AS NOT NULL,
      [Resume] varchar(max) NULL
)
;
BULK INSERT #Applicants
FROM 'c:\test.txt'
WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')
;
insert [dbo].[Applicants]
select AppID, FName, LName, SUBSTRING(LTrim(Resume), 2, LEN(LTrim(Resume))-2)
from #Applicants
Random Solutions  
 
programming4us programming4us