Trouble migrating data from old tables to a new one - sql

I have two tables that I want to replace with a new one. The old tables:
CREATE TABLE [dbo].[OldContacts](
[OldContactID] [int] IDENTITY(1,1) NOT NULL,
[ClientID] [int] NULL,
[BusinessID] [int] NULL,
[Title] [varchar](20) NULL,
[FirstName] [varchar](100) NULL,
[Surname] [varchar](100) NULL,
[JobTitle] [varchar](100) NULL,
[EmailAddress] [varchar](100) NULL,
[Telephone] [varchar](20) NULL,
[Mobile] [varchar](20) NULL,
[DecisionMaker] [int] NULL,
[PrimaryContact] [int] NULL,
[ContactDisabled] [int] NULL,
[ZoomInfoPersonId] [int] NULL,
[CreationDate] [datetime] NULL,
[BusinessListRecordID] [int] NULL)
CREATE TABLE [dbo].[Transaction](
[TransactionId] [int] IDENTITY(1,1) NOT NULL,
[CreditTransactionId] [int] NOT NULL,
[PersonId] [int] NOT NULL,
[CompanyId] [int] NOT NULL,
[CompanyName] [nvarchar](150) NOT NULL,
[ContactName] [nvarchar](150) NOT NULL,
[ContactEmail] [nvarchar](150) NULL,
[ContactPhone] [nvarchar](50) NULL,
[ContactJobTitle] [nvarchar](150) NULL,
[EmailBought] [bit] NULL,
[AddressLine1] [varchar](100) NULL,
[AddressLine2] [varchar](100) NULL,
[AddressLine3] [varchar](100) NULL,
[County] [varchar](100) NULL,
[Town] [varchar](100) NULL,
[Country] [varchar](100) NULL,
[Telephone] [varchar](100) NULL,
[Website] [varchar](500) NULL,
[Industry] [varchar](100) NULL,
[BusinessID] [int] NULL)
And the new one:
CREATE TABLE [dbo].[ClientContacts](
[ClientContactID] [int] IDENTITY(1,1) NOT NULL,
[ClientUserID] [int] NULL,
[PersonID] [int] NULL,
[BusinessID] [int] NULL,
[CompanyID] [int] NULL,
[CompanyName] [varchar](50) NULL,
[ContactName] [varchar](100) NULL,
[ContactFirstName] [varchar](50) NULL,
[ContactSurname] [varchar](50) NULL,
[ContactEmail] [varchar](50) NULL,
[ContactPhone] [varchar](50) NULL,
[ContactMobile] [varchar](50) NULL,
[ContactJobTitle] [varchar](50) NULL,
[EmailBought] [bit] NULL,
[AddressLine1] [varchar](50) NULL,
[AddressLine2] [varchar](50) NULL,
[AddressLine3] [varchar](50) NULL,
[County] [varchar](50) NULL,
[Town] [varchar](50) NULL,
[Country] [varchar](50) NULL,
[CompanyTelephone] [varchar](50) NULL,
[CompanyWebsite] [varchar](50) NULL,
[Industry] [varchar](50) NULL,
[DecisionMaker] [bit] NULL,
[PrimaryContact] [bit] NULL,
[ContactDisabled] [bit] NULL,
[CreationDate] [datetime] NULL,
[BusinessListRecordID] [int] NULL,
[IsPurchased] [bit] NULL
)
The old logic was, you created a record on Transaction, and it would then add a record to OldContacts, creating the redundancy we are now trying to get rid of.
However, you could have a record on OldContacts that didn't come from a Transaction.
Now, I need to migrate the data to the new table, getting all the Transaction records plus the OldContacts that aren't duplicates of the Transaction ones. And here is what I've got so far:
INSERT INTO dbo.ClientContacts
(
ClientUserID, PersonID, BusinessID, CompanyID, CompanyName, ContactName,
ContactFirstName, ContactSurname, ContactEmail, ContactPhone, ContactMobile,
ContactJobTitle, EmailBought, AddressLine1, AddressLine2, AddressLine3,
County, Town, Country, CompanyTelephone, CompanyWebsite, Industry,
DecisionMaker, PrimaryContact, ContactDisabled, CreationDate,
BusinessListRecordID, IsPurchased
)
SELECT
CT.ClientUserId,
LC.ZIPersonId,
LC.BusinessID,
T.CompanyId,
T.CompanyName,
CONCAT(LC.FirstName, ' ', LC.Surname),
LC.FirstName,
LC.Surname,
LC.EmailAddress,
LC.Telephone AS ContactPhone,
LC.Mobile AS ContactMobile,
LC.JobTitle,
T.EmailBought,
T.AddressLine1,
T.AddressLine2,
T.AddressLine3,
T.County,
T.Town,
T.Country,
T.Telephone,
T.Website,
T.Industry,
LC.DecisionMaker,
LC.PrimaryContact,
LC.ContactDisabled,
LC.CreationDate,
LC.BusinessListRecordID,
CASE LC.ZIPersonId WHEN 0 THEN 0 ELSE 1 END
FROM OldContacts LC
LEFT OUTER JOIN dbo.[Transaction] T ON LC.ZIPersonId = T.PersonId
LEFT OUTER JOIN dbo.CreditTransaction CT ON T.CreditTransactionId = CT.CreditTransactionId
However, this only gets me one record, where the ZIPersonId matches. How can I get the records from both tables without getting duplicates?
Here are some test records:
INSERT INTO dbo.OldContacts (ClientID, BusinessID, Title, FirstName, Surname, JobTitle, EmailAddress, Telephone, Mobile, DecisionMaker, PrimaryContact, ContactDisabled, ZIPPersonId, CreationDate, BusinessListRecordID)
VALUES
(13832, 10, 'Mr', 'John55', 'Smith55', 'Admin', 'john55#smith.com', '123456', '123456', 0, 0, 0, 55, GETDATE(), NULL)
INSERT INTO dbo.OldContacts (ClientID, BusinessID, Title, FirstName, Surname, JobTitle, EmailAddress, Telephone, Mobile, DecisionMaker, PrimaryContact, ContactDisabled, ZIPPersonId, CreationDate, BusinessListRecordID)
VALUES
(13832, 10, 'Mr', 'John66', 'Smith66', 'Admin', 'john66#smith.com', '123456', '123456', 0, 0, 0, 66, GETDATE(), NULL)
INSERT INTO dbo.OldContacts (ClientID, BusinessID, Title, FirstName, Surname, JobTitle, EmailAddress, Telephone, Mobile, DecisionMaker, PrimaryContact, ContactDisabled, ZIPPersonId, CreationDate, BusinessListRecordID)
VALUES
(13832, 10, 'Mr', 'John77', 'Smith77', 'Admin', 'john77#smith.com', '123456', '123456', 0, 0, 0, 77, GETDATE(), NULL)
-- ******************************************************************************
INSERT INTO dbo.[Transaction] (CreditTransactionId, PersonId, CompanyId, CompanyName, ContactName, ContactEmail, ContactJobTitle, EmailBought, AddressLine1, AddressLine2, AddressLine3, County, Town, Country, Telephone, Website, Industry, BusinessID)
VALUES
(7965, 77, 123, 'TestCompany', 'John77 Smith77', 'john77#smith77.com', 'Admin', 1, 'AL1','AL2', 'AL3', 'testcounty', 'testtown', 'testcountry', '321456', 'www.test.com', 'someIndustry', 10)
EDIT
I replaced both joins with LEFT OUTER JOINS and I now have all the records. However, I am not getting some columns: no ClientUserId, CompanyId, CompanyName for contacts that come from the OldContacts table and the isPurchased field is always one, when it shouldn't, it should be 1 if the ZIPersonId is not 0.

It seems you have to replace the INNER JOIN with a LEFT JOIN:
INSERT INTO dbo.ClientContacts
(
ClientUserID, PersonID, BusinessID, CompanyID, CompanyName, ContactName,
ContactFirstName, ContactSurname, ContactEmail, ContactPhone, ContactMobile,
ContactJobTitle, EmailBought, AddressLine1, AddressLine2, AddressLine3,
County, Town, Country, CompanyTelephone, CompanyWebsite, Industry,
DecisionMaker, PrimaryContact, ContactDisabled, CreationDate,
BusinessListRecordID, IsPurchased
)
SELECT
CT.ClientUserId,
LC.ZIPersonId,
LC.BusinessID,
T.CompanyId,
T.CompanyName,
CONCAT(LC.FirstName, ' ', LC.Surname),
LC.FirstName,
LC.Surname,
LC.EmailAddress,
LC.Telephone AS ContactPhone,
LC.Mobile AS ContactMobile,
LC.JobTitle,
T.EmailBought,
T.AddressLine1,
T.AddressLine2,
T.AddressLine3,
T.County,
T.Town,
T.Country,
T.Telephone,
T.Website,
T.Industry,
LC.DecisionMaker,
LC.PrimaryContact,
LC.ContactDisabled,
LC.CreationDate,
LC.BusinessListRecordID,
CASE LC.ZIPersonId WHEN 0 THEN 0 ELSE 1 END
FROM OldContacts LC
LEFT JOIN dbo.[Transaction] T ON LC.ZIPersonId = T.PersonId
LEFT JOIN dbo.CreditTransaction CT ON T.CreditTransactionId = CT.CreditTransactionId
This will select the OldContacts even when there are no Transactions or CreditTransaction.
To answer your new question:
CASE LC.ZIPersonId WHEN 0 THEN 0 ELSE 1 END
Should be
CASE T.PersonId WHEN 0 THEN 0 ELSE 1 END

try an union first and then deselect all duplicates in the UNION of
OLDCONTACTS
and
TRANSACTION.
Its hard to replicate your case, I would try something like this:
select the-cols-you-need from
(
select a.the-cols-you-need, a.distinct(foreign-key) from
(
select * from oldcontacts
union all
select * from transaction
) as a
)
inner join CreditTransaction CT on a.transactionId = CT.transactionId

Related

SQL Server Fix Correlated Sub-Queries for Better Performance?

SQL Server 2014
I am trying to learn better SQL code practices to improve performance. I am inheriting some old code, and wanted to get an idea of how someone who actually knows what they're doing would improve it.
I have tried to shorten the code to just the main part I'm working on right now. It seems like there is a better way to get the Reason Codes (PersonalTraining, Tennis, etc.) than running multiple Correlated Subqueries? But, so far I'm having trouble getting the results to return on one row per customer.
The final results must stay the same for a 3rd party.
A customer can have zero to multiple Reason Codes that are stored in the table "asajoinmbr"
Table asajoinmbr:
CREATE TABLE [dbo].[ASAJoinmbr](
[cust_code] [char](10) NOT NULL,
[mbr_code] [char](10) NOT NULL,
[reason_code] [char](3) NULL,
[associate_code] [char](10) NULL,
[join_note] [ntext] NULL,
[wants_contact] [char](1) NULL,
[club] [smallint] NULL,
[region] [char](4) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
Table asamembr:
CREATE TABLE [dbo].[ASAMembr](
[cust_code] [nvarchar](10) NULL,
[mbr_code] [nvarchar](10) NULL,
[lname] [nvarchar](20) NULL,
[fname] [nvarchar](20) NULL,
[status] [nvarchar](6) NULL,
[bdate] [datetime] NULL,
[email] [nvarchar](80) NULL,
[Club] [nvarchar](3) NULL,
) ON [PRIMARY]
Table strcustr:
CREATE TABLE [dbo].[StrCustr](
[cust_code] [nvarchar](10) NULL,
[bridge_code] [nvarchar](10) NULL,
[bus_name] [nvarchar](30) NULL,
[status] [nvarchar](1) NULL,
[phone] [nvarchar](20) NULL,
[address1] [nvarchar](30) NULL,
[address2] [nvarchar](30) NULL,
[city] [nvarchar](20) NULL,
[state] [nvarchar](10) NULL,
[post_code] [nvarchar](10) NULL,
[cntry_abbrev] [nvarchar](3) NULL,
[cust_type] [nvarchar](10) NULL,
[obtained_date] [date] NULL,
[geo_code] [nvarchar](9) NULL,
[email] [nvarchar](80) NULL,
[club] [smallint] NULL,
) ON [PRIMARY]
GO
Any thoughts on improving any part of this code?
select
SC.Club as [Location],
(LTRIM(RTRIM(SC.Cust_Code))+Mem.Mbr_code) as [Customer Number],
Replace(LTRIM(RTRIM(mem.fname)),'"','-') as [Customer First Name],
LTRIM(RTRIM(mem.lname)) as [Customer Last Name],
mem.email as [Customer Email Address],
(select 'Personal Training' from ASAJoinmbr ajm where sc.cust_code =
ajm.cust_code and reason_code = 'PT' group by cust_code) as PersonalTraining,
(select 'Group Fitness' from ASAJoinmbr ajm where sc.cust_code =
ajm.cust_code and (reason_code = 'GE' or reason_code = 'GF') group by
cust_code) as GroupFitness,
(select 'Cardio/Weight'from ASAJoinmbr ajm where sc.cust_code =
ajm.cust_code and (reason_code = 'CT' or reason_code = 'CV' or reason_code =
'WT') group by cust_code) as CardioWeight,
(select 'Tennis'from ASAJoinmbr ajm where sc.cust_code = ajm.cust_code and
(reason_code = 'TE' or reason_code = 'TN') group by cust_code) as Tennis,
(select 'Aquatics' from ASAJoinmbr ajm where sc.cust_code = ajm.cust_code
and reason_code = 'AQ' group by cust_code) as Aquatics
from strcustr SC
INNER JOIN ASAMEMBR MEM
on SC.cust_code=MEM.Cust_code
and sc.club=mem.Club
Where
DATEDIFF(year,(mem.bdate),GETDATE() ) >19
and (DATEDIFF(day, convert(date,sc.obtained_date,101),GETDATE() )= 14
or (DATEDIFF(day, convert(date,sc.obtained_date,101),GETDATE() )=93
and sc.status='A'))
and mem.status = 'A'
and mem.email is not null
and mem.email <>''
and (sc.bridge_code <> '94811' or sc.geo_code <> 'Goldsmbr')
and sc.cust_type<>'E'
group by
sc.club,sc.cust_code,mem.mbr_code,mem.fname,mem.lname,mem.email
Results:

t-sql end of month insert

I have created two database tables named TSALESFACT and DimDate. TSALESFACT table contains the monthly sales target values. And DimTime contains the date values which begins from 01/01/2005.
CREATE TABLE [dbo].[TSalesFact](
[DateID] [smalldatetime] NULL,
[YearID] [int] NOT NULL,
[MonthID] [int] NOT NULL,
[SeasonID] [char](10) NOT NULL,
[DepartmentID] [char](10) NOT NULL,
[SalesAmount] [int] NOT NULL
)
CREATE TABLE [dbo].[dim_Date](
[ID] [int] NOT NULL,
[Date] [datetime] NOT NULL,
[Day] [char](2) NOT NULL,
[DaySuffix] [varchar](4) NOT NULL,
[DayOfWeek] [varchar](9) NOT NULL,
[DOWInMonth] [tinyint] NOT NULL,
[DayOfYear] [int] NOT NULL,
[WeekOfYear] [tinyint] NOT NULL,
[WeekOfMonth] [tinyint] NOT NULL,
[Month] [char](2) NOT NULL,
[MonthName] [varchar](9) NOT NULL,
[Quarter] [tinyint] NOT NULL,
[QuarterName] [varchar](6) NOT NULL,
[Year] [char](4) NOT NULL,
[StandardDate] [varchar](10) NULL,
[HolidayText] [varchar](50) NULL)
I would like to INSERT these sales target values into a new table named DailySalesTargets. But, the main purpose of this operation is writing the target sales to the each of end of month date. All of the date values for the relevant month will be zero. My desired resultset for this operation is like below:
How can I achieve this? Any idea?
I think this is what you are trying to do.
insert into [DailySalesTargets]([DateID],[YearID],[MonthID],
[SeasonID],[DepartmentID],[SalesAmount])
select d.[Date],d.[Year],d.[Month]
,dptSeason.[SeasonID],dptSeason.[DepartmentID]
,case when EOMONTH(d.[Date])=s.[DateID] then s.[SalesAmount] else 0 end as [SalesAmount]
from [dbo].[dim_Date] d
cross join (select distinct [DepartmentID],[SeasonID] from [dbo].[TSalesFact]) dptSeason
left join [dbo].[TSalesFact] s on d.[Date] = s.[DateID]
and s.[DepartmentID]=dptSeason.[DepartmentID]
and s.[SeasonID]=dptSeason.[SeasonID]

Aggregating Rows into a Single row

I am having trouble aggregating a table down into a single row for each customer, the table contains bookings but has duplicate records for different parts of the booking like flight, accommodation, tax, transfer that sort of thing.
I know what columns I have to group by but I just cant seem to get it right
This is what I have so far:
BkgAgentLut
this is a lookup table that contains a single record for each filename and sheet name as filename could have two different sheet names, it brings back a system name which I need to use to define what files im using for that aggregation.
AdvBookings
This is the raw data table that holds the bookings this has to be split into different aggregations I.E( those files that use Micro as its system, those that use Vantage as its system) this is because the two different systems require diofferent group by clauses due to the raw data.
SELECT
Min(URN),
MAX(CAST(bookingdate AS integer)),
MAX(CAST(departuredate AS integer)),
MAX([IdentityValue]) AS [IdentityValue],
MAX(B.[FileName]) AS [FileName],
MAX(B.[SheetName]) AS [SheetName],
MAX([LineNum]) AS [LineNum],
MAX([Title]) AS [Title],
MAX([FirstName]) AS [FirstName],
MAX([Initial]) AS [Initial],
MAX([Surname]) AS [Surname],
MAX([NameLine]) AS [NameLine],
MAX([Addr1]) AS [Addr1],
MAX([Addr2]) AS [Addr2],
MAX([Addr3]) AS [Addr3],
MAX([Addr4]) AS [Addr4],
MAX([Addr5]) AS [Addr5],
MAX([HouseNo]) AS [HouseNo],
MAX([City]) AS [City],
MAX([County]) AS [County],
MAX([Postcode]) AS [Postcode],
MAX([TelNo1]) AS [TelNo1],
MAX([TelNo2]) AS [TelNo2],
SUM(CAST(TotalCost AS MONEY)) AS TotalCost,
NettCost = NULL,
Paid = NULL,
Balance = NULL,
Discount = NULL,
Commission = NULL,
MAX(Adults) AS Adults,
MAX(Children) AS Children,
MAX(Infants) AS Infants,
MAX(Duration) AS Duration,
MAX(PAX) AS PAX,
SUM(CAST(Duration AS INT)) AS Duration,
MAX([DPA1]) AS [DPA1],
MAX([DPA2]) AS [DPA2],
MAX([PrimaryCode]) AS [PrimaryCode],
MAX([SEG]) AS [SEG],
MAX([Month]) AS [Month],
MAX([DeparturePoint]) AS [DeparturePoint],
MAX([ArrivalPoint]) AS [ArrivalPoint],
MAX([HolidayType]) AS [HolidayType],
MAX([TertiaryCode]) AS [TertiaryCode],
MAX([SubTertiaryCode]) AS [SubTertiaryCode],
MAX([Season]) AS [Season],
MAX([HQABTA]) AS [HQABTA],
MAX([BranchABTA]) AS [BranchABTA],
MAX([Company]) AS [Company],
MAX([Clerk]) AS [Clerk],
MAX([FirstRef]) AS [FirstRef],
MAX([SecondRef]) AS [SecondRef],
MAX([Board]) AS [Board],
MAX([EmailAddress]) AS [EmailAddress],
MAX([Direct]) AS [Direct],
MAX([Division]) AS [Division],
MAX([LeadPaxAge]) AS [LeadPaxAge],
MAX([DueDate]) AS [DueDate],
MAX([PreferredMailing]) AS [PreferredMailing],
MAX([Confidential]) AS [Confidential],
MAX([InsuranceNote]) AS [InsuranceNote],
MAX([DOB]) AS [DOB],
MAX([LastDestination]) AS [LastDestination],
MAX([Pax_DOBS]) AS [Pax_DOBS],
MAX([PaymentMethods]) AS [PaymentMethods],
MAX([AirportName]) AS [AirportName],
MAX([Resort]) AS [Resort],
MAX([Hotel]) AS [Hotel],
MAX([HotelLine2]) AS [HotelLine2],
MAX([RoomType]) AS [RoomType],
MAX([PreviousBookings]) AS [PreviousBookings],
MAX([PreviousTravels]) AS [PreviousTravels],
MAX([DestinationList]) AS [DestinationList],
MAX([Tour]) AS [Tour],
MAX([Description]) AS [Description],
MAX([Gender]) AS [Gender],
MAX([TransactionNo]) AS [TransactionNo],
MAX([TransactionType]) AS [TransactionType],
MAX([BusAcctRef]) AS [BusAcctRef],
MAX([BookingStatus]) AS [BookingStatus],
MAX([BranchName]) AS [BranchName],
MAX([OperName]) AS [OperName]
FROM AdvBookings B
LEFT JOIN BkgAgentLut A
ON B.FileName = A.FileName
AND B.SheetName = A.SheetName
WHERE A.[Res System] = 'Vantage'
GROUP BY title,
firstname,
Surname,
addr1,
Addr2,
Addr3,
Addr4,
Postcode,
BookingDate, -- THIS NEEDS TO BE TURNED INTO AN INTEGER SO i CAN USE IT AS A GROUP BY
Departuredate -- THIS NEEDS TO BE TURNED INTO AN INTEGER SO i CAN USE IT AS A GROUP BY
ORDER BY FileName
Tables:
CREATE TABLE [dbo].[AdvBookings](
[IdentityValue] [int] NOT NULL,
[FileName] [varchar](55) NOT NULL,
[SheetName] [varchar](49) NOT NULL,
[LineNum] [int] NOT NULL,
[BookingDate] [datetime] NOT NULL,
[URN] [varchar](8) NULL,
[Title] [varchar](25) NULL,
[FirstName] [varchar](30) NULL,
[Initial] [varchar](5) NULL,
[Surname] [varchar](38) NULL,
[NameLine] [varchar](41) NULL,
[Addr1] [varchar](58) NULL,
[Addr2] [varchar](50) NULL,
[Addr3] [varchar](50) NULL,
[Addr4] [varchar](45) NULL,
[Addr5] [varchar](48) NULL,
[HouseNo] [varchar](5) NULL,
[City] [varchar](25) NULL,
[County] [varchar](31) NULL,
[Postcode] [varchar](19) NULL,
[TelNo1] [varchar](40) NULL,
[TelNo2] [varchar](37) NULL,
[DPA1] [varchar](12) NULL,
[DPA2] [varchar](4) NULL,
[TotalCost] [varchar](19) NULL,
[NettCost] [varchar](20) NULL,
[Paid] [varchar](8) NULL,
[Balance] [varchar](8) NULL,
[Discount] [varchar](8) NULL,
[Commission] [varchar](10) NULL,
[PrimaryCode] [varchar](7) NULL,
[Adults] [varchar](10) NULL,
[Children] [varchar](7) NULL,
[Infants] [varchar](2) NULL,
[Pax] [varchar](7) NULL,
[SEG] [varchar](3) NULL,
[DepartureDate] [datetime] NULL,
[Month] [varchar](19) NULL,
[DeparturePoint] [varchar](22) NULL,
[ArrivalPoint] [varchar](25) NULL,
[HolidayType] [varchar](27) NULL,
[TertiaryCode] [varchar](7) NULL,
[SubTertiaryCode] [varchar](7) NULL,
[Season] [varchar](3) NULL,
[HQABTA] [varchar](7) NULL,
[BranchABTA] [varchar](14) NULL,
[Duration] [varchar](47) NULL,
[Company] [varchar](64) NULL,
[Clerk] [varchar](8) NULL,
[FirstRef] [varchar](20) NULL,
[SecondRef] [varchar](20) NULL,
[Board] [varchar](51) NULL,
[EmailAddress] [varchar](150) NULL,
[Direct] [varchar](66) NULL,
[Division] [varchar](7) NULL,
[LeadPaxAge] [varchar](4) NULL,
[DueDate] [varchar](19) NULL,
[PreferredMailing] [varchar](10) NULL,
[Confidential] [varchar](1) NULL,
[InsuranceNote] [varchar](21) NULL,
[DOB] [datetime] NULL,
[LastDestination] [varchar](42) NULL,
[Pax_DOBS] [varchar](255) NULL,
[PaymentMethods] [varchar](255) NULL,
[AirportName] [varchar](15) NULL,
[Resort] [varchar](52) NULL,
[Hotel] [varchar](180) NULL,
[HotelLine2] [varchar](49) NULL,
[RoomType] [varchar](255) NULL,
[PreviousBookings] [varchar](255) NULL,
[PreviousTravels] [varchar](255) NULL,
[DestinationList] [varchar](255) NULL,
[Tour] [varchar](36) NULL,
[Description] [varchar](169) NULL,
[Gender] [varchar](6) NULL,
[TransactionNo] [varchar](4) NULL,
[TransactionType] [varchar](35) NULL,
[BusAcctRef] [varchar](6) NULL,
[BookingStatus] [varchar](10) NULL,
[BranchName] [varchar](62) NULL,
[OperName] [varchar](50) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO   
CREATE TABLE [dbo].[BkgAgentLut](
[FileName] [nvarchar](255) NULL,
[SheetName] [nvarchar](255) NULL,
[Agent] [nvarchar](255) NULL,
[ABTA] [nvarchar](5) NULL,
[FileName_Rule] [nvarchar](255) NULL,
[Agent_Identification_Rule] [nvarchar](255) NULL,
[ShortName] [nvarchar](255) NULL,
[Res System] [nvarchar](255) NULL,
[ResID] [int] NULL
) ON [PRIMARY]
Sample Data for AdvBookings
IdentityValue,FileName,SheetName,LineNum,BookingDate,URN,Title,FirstName,Initial,Surname,NameLine,Addr,Addr2,Addr3,Addr4,Addr5,HouseNo,City,County,PosNcode,TelNo1,TelNo8,DPA1,DPA2,TotalCost,NettCost,Paid,Balance,Discount,Commission,PrimaryCode,Adults,Children,Infants,Pax,SEG,DepartureDate,Month,DeparturePoint,ArrivalPoint,HolidayType,TertiaryCode,SubTertiaryCode,Season,HQABTA,BranchABTA,Duration,Company,Clerk,FirstRef,SecondRef,Board,EmailAddress,Direct,Division,LeadPaxAge,DueDate,PreferredMailing,Confidential,InsuranceNote,DOB,LastDestination,Pax_DOBS,PaymentMethods,AirportName,Resort,Hotel,HotelLine2,RoomType,PreviousBookings,PreviousTravels,DestinationList,Tour,Description,Gender,TransactionNo,TransactionType,BusAcctRef,BookingStatus,BranchName,OperName
145990,ATE_L389X_20140902044749.CSV,ATE_L389X_20140902044749.CSV,1,00:00.0,385221,Mr,W,W,Sousa,NULL, David Moon Hosue,Devonshire Place,St Helier,NULL,NULL,NULL,NULL,NULL,KE2 3DP,864886,07797 748 173 Daught,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,1,0,0,1,NULL,00:00.0,NULL,JER,FNC,Summer Sun,NULL,NULL,NULL,NULL,L389X,14,ESTR,NULL,NULL,NULL,<No BoardBasis Defined>,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Funchal,Residencial Parque,NULL,NULL,NULL,NULL,Portugal,NULL,NULL,Male,2,Package Holiday,NULL,D,Bellingham Travel St Helier,Estrela Travel
1410709,ATE_Howard_20140901162839.CSV,ATE_Howard_20140901162839.CSV,1,00:00.0,8866,Mr,W,W,Coward,NULL, Southwood Road,Trowbridge,Wiltshire,NULL,NULL,NULL,NULL,NULL,BA647BZ,01885 666638,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,2,2,0,4,NULL,00:00.0,NULL,NULL,NULL,Cruise,NULL,NULL,NULL,NULL,92943,NULL,MCRU,NULL,NULL,NULL,NULL,carol.coward#blueyonder.co.uk,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Male,4,Cruise,NULL,D,Howard Travel,Misc Cruise
470590,AdvantageData 31 August.xlsx,'CBT Travel$',1,49:59.0,5035,Mr.,q,q,Hudson,NULL, Harlech Close,Haslingden,Rossendale,Lancashire,NULL,NULL,NULL,NULL,BB4 6NL,NULL,NULL,NULL,NULL,1729,1653,NULL,NULL,76,NULL,NULL,2,0,0,NULL,NULL,00:00.0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,11,Royal Caribbean Cruise Line,NULL,NULL,NULL,Full Board,NULL,NULL,NULL,NULL,NULL,NULL,N,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Eastern Caribbean,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
496438,ALTHAMS_20140907.csv,ALTHAMS_20140907.csv,1,00:00.0,2004019,Mr,D,D,Cooper,NULL, Ullswater Close,Rishton,Blackburn,NULL,NULL,NULL,NULL,NULL,BB64EP,1854888480,NULL,Y,N,2206.24,NULL,2206.24,0,NULL,265.74,CNT,2,0,NULL,2,TP,00:00.0,Sep,MANCHESTER,NULL,NULL,REG,NULL,S10,11626,NULL,14,THOMSON,CT1,2771894,NULL,HB,NULL,NULL,ACC,65,06/07/2010,P,N,INSURANCE ISSUED,NULL,NULL,NULL,NULL,NULL,SANTORINI,VENUS BEACH,NULL,1 DOUBL3 SH WC BL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
1455951,ATE_C5649_20140903155313.CSV,ATE_C5649_20140903155313.CSV,1,00:00.0,64512,Mr,W,W,O Donnell,NULL, Derrycarib Road,NULL,Portadown,Co Armagh,NULL,NULL,NULL,NULL,BN62 6UY,NULL,7716080365,NULL,NULL,12,NULL,NULL,NULL,NULL,NULL,NULL,1,0,0,1,NULL,00:00.0,NULL,NULL,NULL,Summer Sun,NULL,NULL,NULL,NULL,C5649,NULL,MISC,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Male,2,Misc Item,NULL,D,Terra - C5649,Misc Account - Ukl Bookings
329035,HOLIDAYTVL_20140907.csv,HOLIDAYTVL_20140907.csv,1,00:00.0,1065539,Mr,PATRICK,P,Moody,NULL, Tennyson Avenue,Bridlington,East Yorkshire,NULL,NULL,NULL,NULL,NULL,YO65 2EX,6866661564,NULL,N,N,523,NULL,523,0,NULL,62.76,BCH,1,0,NULL,1,ST,00:00.0,Jun,TON,NULL,NULL,NULL,NULL,S10,35404,35404,7,SHEARINGS,RLH,M13291,NULL,HALF BOARD,NULL,NULL,NULL,NULL,27/03/2010,P,N,INS. DECLINED,NULL,NULL,NULL,NULL,NULL,"OBAN,MULL & IONA",GREAT WESTERN,NULL,SINGLE ROOM WITH A SEA VIEW,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
396525,REGAL_20140907.csv,REGAL_20140907.csv,1,00:00.0,1070979,Mrs,JANET,W,Hoskins,NULL, St David'S Close,Wild Mill,Bridgend,NULL,NULL,NULL,NULL,NULL,CF36 6RR,01656 658865,NULL,N,N,1106.55,NULL,1078,0,NULL,97.73,SSU,2,0,NULL,2,TP,00:00.0,Jul,"CARDIFF,UK",NULL,NULL,BUS,NULL,S10,71538,71538,10,THOMAS COOK,CLA,T122485N, BUS,HALF BOARD,NULL,NULL,NULL,46,02/05/2010,P,N,JTI10A-38338146,00:00.0,NULL,NULL,NULL,NULL,MONASTIR,ROYAL KENZ,NULL,1 TWIN3 B S WC BAL/TER : PORT EL KANTAOUI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Regal Travel - 71538,NULL
417902,TicketsAnywhere_20140831.tab,TicketsAnywhere_20140831.tab,1,00:00.0,100,Mrs,Tanya,NULL,Farrer,NULL, Merton Road,NULL,NULL,NULL,NULL,NULL,Princes Risborough,Bucks,PP27 0DR,0660 943 8015,NULL,NULL,NULL,18.5,18.5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,00:00.0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,8932X,0,Ultrasun Sun cream,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Ultrasun sun cream,NULL,NULL,Ultrasun Sun cream,NULL
437608,TRAVELTIMEWORLD_20140907.csv,TRAVELTIMEWORLD_20140907.csv,1,00:00.0,3012302,Miss,LYNN,L,Guthrie,NULL,Nb Crystal,White Lion Wharf,Star Tops End Marsworth,NULL,NULL,NULL,NULL,NULL,PP23 4LK,1448,7756854687,N,N,541.9,NULL,541.9,0,NULL,27.6,LHV,1,0,NULL,1,ST,00:00.0,Feb,LH4,NULL,NULL,RPT,NULL,L,F2256,F2256,70,JETSET,ASH,3268399,NULL,NULL,NULL,NULL,NULL,NULL,02/01/2010,P,N,CLIENT DECLINED,NULL,NULL,NULL,NULL,NULL,ACCRA,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
447594,AdvantageData 31 August.xlsx,'Apex Rhuddlan$',1,56:23.0,6618,Mrs.,C,C,Morris,NULL, Heol Hendre,Rhuddlan,Denbighshire,NULL,NULL,NULL,NULL,NULL,LL68 5PG,NULL,NULL,NULL,NULL,418,418,NULL,NULL,0,NULL,NULL,2,0,0,NULL,NULL,00:00.0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,4,Alfa Travel Ltd,NULL,NULL,NULL,Half Board,NULL,NULL,NULL,NULL,NULL,NULL,N,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Vardiff And The Valleys,NULL,NULL,NULL,NULL,NULL,Alfa Travel - Free Insurance Offer,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
457205,AdvantageData 31 August.xlsx,'Baldwins Tenterden $',1,39:56.0,56,Mr.,P,P,Sabin,NULL,Woodcote,Woodchurch Road,Tenterden,NULL,NULL,NULL,NULL,NULL,NN30 7AD,NULL,NULL,NULL,NULL,3412.98,3362.98,NULL,NULL,50,NULL,NULL,2,0,0,NULL,NULL,00:00.0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,16,Celebrity Cruises,NULL,NULL,NULL,Full Board,NULL,NULL,NULL,NULL,NULL,NULL,N,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Exotic Southern Caribbean,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
457821,AdvantageData 31 August.xlsx,'Baldwins Tonbridge$',1,04:03.0,14179,Mr.,K,K,Hill,NULL,Lodge Farm Oast,Bramble Reed Lane,Matfield,Kent,NULL,NULL,NULL,NULL,NN62 7EN,NULL,NULL,NULL,NULL,5239,5239,NULL,NULL,0,NULL,NULL,2,2,0,NULL,NULL,30:00.0,NULL,LGW,PVK,NULL,NULL,NULL,NULL,NULL,NULL,14,Travelux Ltd,NULL,NULL,NULL,Self Catering,NULL,NULL,NULL,NULL,NULL,NULL,N,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Villa Votsalo,NULL,NULL,NULL,NULL,NULL,Greece / Lefkada,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
285347,CH Advantage_Report upto 31aug14.tab,CH Advantage_Report upto 31aug14.tab,1,00:00.0,7785,Mr,Mark,NULL,Saunders,NULL, Whitehall Road,NULL,NULL,NULL,NULL,NULL,Toronto,Ontario,M4W 2C5,14166886488,NULL,NULL,NULL,60,60,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,4,NULL,00:00.0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,K4373,0,Out`N`About,NULL,NULL,NULL,NULL,linda.saunders#rogers.com,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Airport transfers,NULL,NULL,Out`N`About,NULL
81365,ATE_56665_20140902040159.CSV,ATE_56665_20140902040159.CSV,1,00:00.0,1295,Mrs,W,W,Green,NULL,C/O Mr & Mrs P Wanstall,2 Wellfield,Hartley,Kent,NULL,NULL,NULL,NULL,DA3 7EQ,01464 606 915,7957830380,NULL,NULL,2304,NULL,NULL,NULL,NULL,NULL,NULL,2,0,0,2,NULL,00:00.0,NULL,LGW,HOG,Longhaul,NULL,NULL,NULL,NULL,56665,14,TCH,NULL,NULL,NULL,<No BoardBasis Defined>,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Playa Pesquero,Hotel Playa Pesquero,NULL,NULL,NULL,NULL,Cuba,NULL,NULL,Female,1,Bonded Package,NULL,D,Sunways Travel,Thomas Cook Holidays
1056744,ATE_L3885_20140902045317.CSV,ATE_L3885_20140902045317.CSV,1,00:00.0,388377,Ms,Ann,A,Shanahan,NULL, Landscape Grove,St Helier,Jersey,Channel Islands,NULL,NULL,NULL,NULL,KE2 3KU,644168,077977 44186,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,4,0,0,4,NULL,00:00.0,NULL,NULL,NULL,<No Type Defined>,NULL,NULL,NULL,NULL,L3885,3,SBK,NULL,NULL,NULL,<No BoardBasis Defined>,ann.shanahan#bedellgroup.com ann_shanahan#hotmail.com,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,To Be Advised,NULL,2 X Twins,NULL,NULL,NULL,NULL,NULL,Male,2,Hotels Foreign,NULL,D,Bellingham Travel St Brelade,Superbreaks
1420142,ATE_G1255_20140903152628.CSV,ATE_G1255_20140903152628.CSV,1,00:00.0,13922,Mr,C,C,Bushby,NULL,The Well House,Strait Lane,"Huby, Leeds",West Yorkshire,NULL,NULL,NULL,NULL,LS67 0EA,633361,L 07050811894,NULL,NULL,5770,NULL,NULL,NULL,NULL,NULL,NULL,3,0,0,3,NULL,00:00.0,NULL,LHR,MRU,Longhaul,NULL,NULL,NULL,NULL,G1255,10,IFON,NULL,NULL,NULL,<No BoardBasis Defined>,bushby#bigfastweb.net,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Mauritius,Le Touessrok,NULL,NULL,NULL,NULL,Mauritius,NULL,NULL,Male,1,Std Package Hol,NULL,D,Number One Travel,If Only Holidays Ltd
468921,AdvantageData 31 August.xlsx,'Baldwins Uckfield$',1,14:41.0,1,Mr.,W,W,Taylor,NULL, Hart Close,Uckfield,East Sussex,NULL,NULL,NULL,NULL,NULL,NN22 2DA,NULL,NULL,NULL,NULL,3058.2,3058.2,NULL,NULL,0,NULL,NULL,2,0,0,NULL,NULL,00:00.0,NULL,LHR,MRU,NULL,NULL,NULL,NULL,NULL,NULL,7,Enchanting Holidays,NULL,NULL,NULL,All Inclusive,NULL,NULL,NULL,NULL,NULL,NULL,N,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Le Meridien Ile Maurice,NULL,NULL,NULL,NULL,NULL,Mauritius,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
760382,ATE_33466_20140902043502.CSV,ATE_33466_20140902043502.CSV,1,00:00.0,3,Mr,I,I,Test,NULL,Test,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,1,0,0,1,NULL,00:00.0,NULL,NULL,NULL,<No Type Defined>,NULL,NULL,NULL,NULL,33466,NULL,RAIE,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Male,1,Motorail,NULL,D,Travelwise Handforth,French Motorail
769599,ATE_2585X_20140903154534.CSV,ATE_2585X_20140903154534.CSV,1,00:00.0,1,Mr,D,D,Keenan,NULL, Redcar Drive,Eastham,Wirral,NULL,NULL,NULL,NULL,NULL,CP62 8PE,01515130466-Daniel,NULL,NULL,NULL,1900,NULL,NULL,NULL,NULL,NULL,NULL,2,0,0,2,NULL,00:00.0,NULL,NULL,NULL,Cruise,NULL,NULL,NULL,NULL,2585X,NULL,PAGE,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Male,1,Cruise,NULL,D,Dalton Travel Dunmow,Page & Moy Ltd
1535988,ATE_81633_20140902043127.CSV,ATE_81633_20140902043127.CSV,1,00:00.0,823,Mrs,W,W,Fairhurst,NULL,Chapel House,Arkholme,CARNFORTH,Lancashire,NULL,NULL,NULL,NULL,LA6 6AX,015848 81454,NULL,NULL,NULL,71.9,NULL,NULL,NULL,NULL,NULL,NULL,1,0,0,1,NULL,00:00.0,NULL,NULL,NULL,<No Type Defined>,NULL,NULL,NULL,NULL,81633,NULL,RAIL,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Female,1,Rail Ticket,NULL,D,Gates Travel Kendal,ATOC
1910689,ATE_68605_20140903155212.CSV,ATE_68605_20140903155212.CSV,1,00:00.0,46357,Mr,Jonathan,W,Brady,NULL, Lynden Gate Park,Portadown,NULL,Co Armagh,NULL,NULL,NULL,NULL,BN63 5YP,6610804168,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,2,0,0,2,NULL,00:00.0,NULL,BFS,<No Dest D,Summer Sun,NULL,NULL,NULL,NULL,68605,2,SOLU,NULL,NULL,NULL,<No BoardBasis Defined>,NULL,NULL,3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Alton Towers,Best Western Moathouse,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Male,2,Package/Ft Only,NULL,D,Terra Travel Lurgan,Travel Solutions
1943852,ATE_61659_20140903154707.CSV,ATE_61659_20140903154707.CSV,1,00:00.0,1,Mr,N,N,Express,NULL,.,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,1,0,0,1,NULL,00:00.0,NULL,NULL,NULL,National Xpress,NULL,NULL,NULL,NULL,61659,NULL,NEX,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Male,6,Miscellaneous,NULL,D,AirViceroy,National Express
206859,ATE_75543_20140807124842.CSV,ATE_75543_20140807124842.CSV,1,00:00.0,168,Mrs,K,K,Scott,NULL, Twining Avenue,Twickenham,Middlesex,NULL,NULL,NULL,NULL,NULL,NW2 5LP,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,3,0,0,3,NULL,00:00.0,NULL,LGW,IST,Summer Sun,NULL,NULL,NULL,NULL,75543,7,PLAN,NULL,NULL,NULL,<No Board Basis Defined>,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Limassol,Blue Crane Apts,NULL,NULL,NULL,NULL,Turkey,NULL,NULL,Female,1,Std Package Hol,NULL,D,Thames Travel,Planet Holidays
207037,ATE_P5549_20140903153751.CSV,ATE_P5549_20140903153751.CSV,1,00:00.0,41813,Mr,S,S,Rawson,NULL, Wike Ridge Mount,Leeds,NULL,NULL,NULL,NULL,NULL,NULL,LS67 9NP,6984916306,NULL,NULL,NULL,1040.6,NULL,NULL,NULL,NULL,NULL,NULL,1,0,0,1,NULL,00:00.0,NULL,MAN,MEL,<No Type Defined>,NULL,NULL,NULL,NULL,P5549,NULL,JSET,NULL,NULL,NULL,.,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Australia,NULL,NULL,Male,1,Consolidation,NULL,D,Top Choice Holidays,Jetset Tours
226820,ATE_P6140_20140902041603.CSV,ATE_P6140_20140902041603.CSV,1,00:00.0,1548,Mrs,K,K,Kells,NULL,Granville House,Barrack Lane,Lilleshall,Nr Newport Shropshire,NULL,NULL,NULL,NULL,NF60 9ER,1958666661,NULL,TRUE,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,2,0,0,2,NULL,00:00.0,NULL,NULL,NULL,Summer Sun,NULL,NULL,NULL,NULL,P6140,7,THOS,NULL,NULL,NULL,<No BoardBasis Defined>,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Breadsall,Priory,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Female,2,Package Holiday,NULL,D,Roma Travel Keyworth,Thomas Cook Group Ltd
237560,ATE_P6603_20140903154136.CSV,ATE_P6603_20140903154136.CSV,1,00:00.0,59664,Mrs,Jayne,W,Yeomans,NULL,Oswestry,NULL,NULL,Shropshire,NULL,NULL,NULL,NULL,SY66 2LW,1691658111,7763979418,NULL,NULL,1612,NULL,NULL,NULL,NULL,NULL,NULL,2,0,0,2,NULL,00:00.0,NULL,MAN,PFO,Summer Sun,NULL,NULL,NULL,NULL,P6603,7,THOM,NULL,NULL,NULL,<No BoardBasis Defined>,jayne4467yeomans#aol.com,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Paphos,Louis Phaethon Beach Club,NULL,NULL,NULL,NULL,Cyprus,NULL,NULL,Female,1,Package Holiday,NULL,D,PolkaDot Travel,Thomson Holidays Ltd
249315,ATE_K5624_20140902043254.CSV,ATE_K5624_20140902043254.CSV,1,00:00.0,216,Mr,EW,EW,Murray,NULL,a Linton Close,Newark,NULL,Notts,NULL,NULL,NULL,NULL,NG244NQ,666146,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,2,2,0,4,NULL,00:00.0,NULL,NULL,NULL,Coach Tours Uk,NULL,NULL,NULL,NULL,K5624,4,TRWH,NULL,NULL,NULL,<No BoardBasis Defined>,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Skegness Contra,De Vere Mottram Hall Hotel,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Male,2,Std Package Hol,NULL,D,Roma - Newark,Travel Wright Ltd
263146,ATE_P6621_20140903153607.CSV,ATE_P6621_20140903153607.CSV,1,00:00.0,34393,Mrs,A,A,White,NULL, Glen Rise,Belfast,NULL,NULL,NULL,NULL,NULL,NULL,BN5 7LF,8890940015,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,2,0,0,2,NULL,00:00.0,NULL,BFS,SYD,<No Type Defined>,NULL,NULL,NULL,NULL,P6621,NULL,BSP,NULL,NULL,NULL,<No Board Basis Defined>,markana#virginmedia.com,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,Australia,NULL,NULL,Female,1,Air Tickets,NULL,E,Breakaway Travel Shankill Road Belfast,B S P ( U K )
script to change the data types:
    
SELECT CAST([IdentityValue] as bigint)[IdentityValue]
,[FileName]
,[SheetName]
,CAST([LineNum] AS INT) [LineNum]
,CAST([BookingDate] AS INT) [BookingDate]
,CAST([URN] AS INT) [URN]
,[Title]
,[FirstName]
,[Initial]
,[Surname]
,[NameLine]
,[Addr1]
,[Addr2]
,[Addr3]
,[Addr4]
,[Addr5]
,[HouseNo]
,[City]
,[County]
,[Postcode]
,[TelNo1]
,[TelNo2]
,[DPA1]
,[DPA2]
,CAST([TotalCost] AS MONEY) [TotalCost]
,CAST([NettCost] AS MONEY) [NettCost]
,[Paid]
,[Balance]
,CAST([Discount] AS MONEY) [Discount]
,[Commission]
,[PrimaryCode]
,CAST([Adults] AS INT) [Adults]
,CAST([Children] AS INT) [Children]
,CAST([Infants] AS INT) [Infants]
,[Pax]
,[SEG]
,CAST([DepartureDate]
,[Month]
,[DeparturePoint]
,[ArrivalPoint]
,[HolidayType]
,[TertiaryCode]
,[SubTertiaryCode]
,[Season]
,[HQABTA]
,[BranchABTA]
,CAST([Duration] AS INT) [Duration]
,[Company]
,[Clerk]
,[FirstRef]
,[SecondRef]
,[Board]
,[EmailAddress]
,[Direct]
,[Division]
,[LeadPaxAge]
,[DueDate]
,[PreferredMailing]
,[Confidential]
,[InsuranceNote]
,[DOB]
,[LastDestination]
,[Pax_DOBS]
,[PaymentMethods]
,[AirportName]
,[Resort]
,[Hotel]
,[HotelLine2]
,[RoomType]
,[PreviousBookings]
,[PreviousTravels]
,[DestinationList]
,[Tour]
,[Description]
,[Gender]
,[TransactionNo]
,[TransactionType]
,[BusAcctRef]
,[BookingStatus]
,[BranchName]
,[OperName]
INTO CustStg
FROM AdvBookings
Apologies as this is too large for a comment and might not be considered an answer.
Compare these 2 queries: The first of these will not produce any rows whatsoever unless A.[Res System] = 'Vantage'
select 'use where condition', b.*
FROM AdvBookings B
LEFT JOIN BkgAgentLut A
ON B.FileName = A.FileName
AND B.SheetName = A.SheetName
WHERE A.[Res System] = 'Vantage'
;
The second of those queries will list all records from AdvBookings even if A.[Res System] = 'Vantage' is not true.
select 'use join condition', b.*
FROM AdvBookings B
LEFT JOIN BkgAgentLut A
ON B.FileName = A.FileName
AND B.SheetName = A.SheetName
AND A.[Res System] = 'Vantage'
The difference is how the condition is applied. In the first query you have an "implied inner join" because every row HAS TO comply with the where clause. In the second you have a LEFT JOIN with conditions and this does not prohibit rows from being listed from AdvBookings.
For the rest of your question you need to provide sample data that will illustrate your problem. I could not find any BUT I was using SQLFiddle and this limits DDL to 8000 characters so I could only get a few rows inserted. Also the datetime information you have provided seems to be only contain time.
see: http://sqlfiddle.com/#!3/646fc/5
For the few records I did get inserted I had no specific problem with your query.

Mssql old table to new table different data types and empties

I have a new table I created for a membership application for a local club, anyway there existing software stored info in a DBF file I can import this into mssql as a table that's no trouble I am just stuck on merging the old data into the new table.
This is the old Table Structure (From DBF imported into mssql)
[NUMBER] [int] NULL,
[LASTNAME] [char](30) NULL,
[FIRSTNAME] [char](20) NULL,
[TITLE] [char](5) NULL,
[SALUTATION] [char](25) NULL,
[ADD1] [char](30) NULL,
[ADD2] [char](30) NULL,
[ADD3] [char](30) NULL,
[TOWN] [char](30) NULL,
[COUNTY] [char](30) NULL,
[POSTCODE] [char](8) NULL,
[TELEPHONE] [char](30) NULL,
[TYPE] [char](1) NULL,
[PAID] [char](1) NULL,
[COMMITTEE] [char](30) NULL,
[WARNINGS] [int] NULL,
[MONTHDRAW] [int] NULL,
[WOMANS] [char](1) NULL,
[SENIORCIT] [char](1) NULL,
[DOB] [datetime] NULL,
[AMOUNTCLUB] [decimal](6, 2) NULL,
[DATEPAY] [datetime] NULL,
[AMOUNTBRAN] [decimal](6, 2) NULL,
[AMOUNTDUE] [decimal](6, 2) NULL
This is the new Table:
[MemberID] [nvarchar](10) NOT NULL,
[Title] [nvarchar](10) NOT NULL,
[FirstName] [nvarchar](50) NOT NULL,
[Surname] [nvarchar](50) NOT NULL,
[HouseNumber] [nvarchar](25) NULL,
[Street] [nvarchar](25) NULL,
[City] [nvarchar](25) NULL,
[County] [nvarchar](25) NULL,
[Postcode] [nvarchar](10) NULL,
[TelephoneNumber] [nvarchar](15) NULL,
[MobileNumber] [nvarchar](15) NULL,
[EmailAddress] [nvarchar](50) NULL,
[DOB] [date] NULL,
[Age] [nvarchar](10) NULL,
[SeniorCitizen] [nvarchar](5) NULL,
[Warnings] [nvarchar](50) NULL,
[MembershipCategory] [nvarchar](20) NULL,
[ServiceBranch] [nvarchar](20) NULL,
[Paid] [nvarchar](10) NULL,
[ToPay] [float] NULL,
[DatePaidIn] [date] NULL,
[Entry] [tinyint] NULL,
[FOB] [nvarchar](10) NULL,
[JoinDate] [date] NULL,
[SubscriptionYear] [date] NULL,
[TotalPaid] [float] NULL,
I am writing the insert like;
INSERT INTO [dbo].[MemberDetails]
([MemberID],[Title],[FirstName],[Surname],[HouseNumber],[Street],[City],[County],[Postcode],[TelephoneNumber],[MobileNumber],[EmailAddress],[DOB],[Age],[SeniorCitizen],[Warnings],[MembershipCategory],[ServiceBranch],[Paid],[ToPay],[DatePaidIn],[Entry],[FOB],[JoinDate],[SubscriptionYear],[TotalPaid])
SELECT [NUMBER], [TITLE], [FIRSTNAME], [LASTNAME], [ADD1], [ADD2], [TOWN], [COUNTY], [POSTCODE], [TELEPHONE]
FROM [dbo].[MEMBERS]
GO
I got as far as that column then realized "how do I do empty values as no one in the old table had a mobile record?" also do I need to do Select AS "new column name" for the old table values?
Suppose you go from OldTable to NewTable, adding an answer column to the original question column:
insert NewTable
(question, answer)
select question
, '42' -- Specify a literal or default value
from OldTable
You can also omit the new column from the insert list:
insert NewTable
(question)
select question
from OldTable
This will copy the question column and put the default value null in the answer column.
You do not have to use aliases in the select list. It's strictly order based. This would work fine:
insert NewTable
(question)
select question as CeciNEstPasUnePipe
from OldTable

SQL to XML Output

I was hoping I could get some help with this last part of a somewhat complicated problem I have been working on.
We have to produce an XML file from a SQL table that we are generating.
At its core the XML needs three elements.
Patient
PhoneAssessment
F2FAssessment
This is working as I'll show in my test code. However, the one problem we have is that if someone has both a F2FAssessment and a PhoneAssessment it will generate multiple tags.
If you all could give me some insight on the best way to fix this to where there will only be one Patient tag that contains all possible PhoneAssessment and F2FAssessment tags it would be greatly appreciated.
Here is the SQL code:
use tempdb;
declare #t table
(
[people_id] [nvarchar](255) NULL,
[actual_date] [date] NULL,
[NPI] [int] NULL,
[FileCreationDate] [date] NULL,
[FileCreationTime] [time](7) NULL,
[ProviderPatientNo] [int] NULL,
[LastName] [nvarchar](255) NULL,
[FirstName] [nvarchar](255) NULL,
[SSN] [nvarchar](255) NULL,
[DOB] [date] NULL,
[Gender] [int] NULL,
[Race] [int] NULL,
[Ethnicity] [int] NULL,
[ProviderPhoneAssessmentId] [nvarchar](255) NULL,
[CallEndDate] [date] NULL,
[CallEndTime] [time](7) NULL,
[DispatchDate] [date] NULL,
[DispatchTime] [time](7) NULL,
[CallDisposition] [int] NULL,
[DispositionOther] [nvarchar](255) NULL,
[Notes] [nvarchar](255) NULL,
[ProviderF2FAssessmentId] [nvarchar](255) NULL,
[AssessmentDate] [date] NULL,
[ArrivalTime] [time](7) NULL,
[ResidentialStatus] [int] NULL,
[County] [int] NULL,
[EmploymentStatus] [int] NULL,
[MaritalStatus] [int] NULL,
[MilitaryStatus] [int] NULL,
[NumArrests30Days] [nvarchar](255) NULL,
[AttendedSchoolLast3Months] [int] NULL,
[EducationLevel] [int] NULL,
[PrimaryPayorSource] [int] NULL,
[SecondaryPayorSource] [int] NULL,
[AnnualHouseholdIncome] [int] NULL,
[NumberInHousehold] [int] NULL,
[CurrentServices] [int] NULL,
[MHTreatmentDeclaration] [int] NULL,
[MOTStatus] [int] NULL,
[DurablePOA] [int] NULL,
[AssessmentLocation] [nvarchar](255) NULL,
[TransportedByLE] [int] NULL,
[TelevideoAssessment] [int] NULL,
[CurrentDetoxSymptoms] [int] NULL,
[HistoryOfDetoxSymptoms] [int] NULL,
[PrimaryDSMDiagnosis] [nvarchar](255) NULL,
[SecondaryDSMDiagnosis] [nvarchar](255) NULL,
[CompletedByLastName] [nvarchar](255) NULL,
[CompletedByFirstName] [nvarchar](255) NULL,
[DateDispositionCompleted] [date] NULL,
[TimeDispositionCompleted] [time](7) NULL,
[RecommendedTransportMode] [int] NULL,
[DateTransportedToFacility] [date] NULL,
[TimeTransportedToFacility] [time](7) NULL,
[FollowupContacted] [nvarchar](255) NULL,
[FollowupReportedServiceHelpful] [nvarchar](255) NULL,
[ContactAttempts] [nvarchar](255) NULL,
[VoluntaryAdmissionRecommended] [nvarchar](255) NULL,
[AdmissionAssessmentViaTelehealth] [nvarchar](255) NULL,
[IsAdmitted] [nvarchar](255) NULL,
[FirstHospitalization] [nvarchar](255) NULL,
[PrimaryProblem] [nvarchar](255) NULL,
[IntellectualDisability] [int] NULL,
[MedicalInstability] [int] NULL,
[MedicationIssues] [int] NULL,
[PastTrauma] [int] NULL,
[SubstanceAbuse] [int] NULL,
[Drug] [int] NULL,
[DrugRoute] [int] NULL,
[DrugFrequency] [int] NULL,
[HospAlternative] [nvarchar](255) NULL,
[HospAltDisposition] [nvarchar](255) NULL,
[Hospitalization] [nvarchar](255) NULL,
[HospitalizationDisposition] [nvarchar](255) NULL,
[SCS_Stf_Recommend] [nvarchar](255) NULL
)
insert INTO #t
([people_id],[actual_date],[NPI],[FileCreationDate],[FileCreationTime],[ProviderPatientNo],[LastName],[FirstName],[SSN],[DOB],[Gender],[Race],[Ethnicity],[ProviderPhoneAssessmentId],[CallEndDate],[CallEndTime],[DispatchDate],[DispatchTime],[CallDisposition],[DispositionOther],[Notes],[ProviderF2FAssessmentId],[AssessmentDate],[ArrivalTime],[ResidentialStatus],[County],[EmploymentStatus],[MaritalStatus],[MilitaryStatus],[NumArrests30Days],[AttendedSchoolLast3Months],[EducationLevel],[PrimaryPayorSource],[SecondaryPayorSource],[AnnualHouseholdIncome],[NumberInHousehold],[CurrentServices],[MHTreatmentDeclaration],[MOTStatus],[DurablePOA],[AssessmentLocation],[TransportedByLE],[TelevideoAssessment],[CurrentDetoxSymptoms],[HistoryOfDetoxSymptoms],[PrimaryDSMDiagnosis],[SecondaryDSMDiagnosis],[CompletedByLastName],[CompletedByFirstName],[DateDispositionCompleted],[TimeDispositionCompleted],[RecommendedTransportMode],[DateTransportedToFacility],[TimeTransportedToFacility],[FollowupContacted],[FollowupReportedServiceHelpful],[ContactAttempts],[VoluntaryAdmissionRecommended],[AdmissionAssessmentViaTelehealth],[IsAdmitted],[FirstHospitalization],[PrimaryProblem],[IntellectualDisability],[MedicalInstability],[MedicationIssues],[PastTrauma],[SubstanceAbuse],[Drug],[DrugRoute],[DrugFrequency],[HospAlternative],[HospAltDisposition],[Hospitalization],[HospitalizationDisposition],[SCS_Stf_Recommend])
VALUES
('90F07844-746A-4347-82CA-39D4332B43F3','2013-09-25','1306875695','2014-02-12','15:19:37.0000000','108677','David','Joe','414555555','1999-01-23','2','1','2','59DC25C9-B659-42A3-B43D-26C741F9B929','2013-09-26','15:17:00.0000000',NULL,NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,'87',NULL,'6','4',NULL,NULL,NULL,'9','9',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'LastName','Alisha','2013-09-26','15:17:00.0000000',NULL,NULL,NULL,'0',NULL,NULL,NULL,NULL,'0',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
('90F07844-746A-4347-82CA-39D4332B43F3','2013-09-25','1306875695','2014-02-12','15:19:37.0000000','108677','David','Joe','414555555','1999-01-23','2','1','2',NULL,'2013-09-25','18:45:00.0000000','2013-09-25','18:51:00.0000000','4',NULL,NULL,'35159D47-32B2-445C-A905-019E191FDDE2','2013-09-25','19:22:00.0000000','13','47','12','6','4',NULL,'3','23','8','9','0','4','8','3','3','3','4','0','0','0','0','V71.09 ','V71.09','Tweed','A','2013-09-25','21:10:51.0000000','3',NULL,NULL,'1','1',NULL,'0','0','0',NULL,'2','3','3','3','3','2',NULL,NULL,NULL,'8','4',NULL,NULL,NULL)
IF OBJECT_ID('tempdb.dbo.#Patient') IS NOT NULL drop table #Patient
IF OBJECT_ID('tempdb.dbo.#Drugs') IS NOT NULL drop table #Drugs
IF OBJECT_ID('tempdb.dbo.#Assessments') IS NOT NULL drop table #Assessments
IF OBJECT_ID('tempdb.dbo.#HospAlt') IS NOT NULL drop table #HospAlt
IF OBJECT_ID('tempdb.dbo.#HospDisp') IS NOT NULL drop table #HospDisp
IF OBJECT_ID('tempdb.dbo.#PatientDistinct') IS NOT NULL drop table #PatientDistinct
--Patient Distinct
select distinct
ProviderPatientNo
into #PatientDistinct
FROM #t
--Patients
select distinct
NPI,
FileCreationDate,
FileCreationTime,
ProviderPatientNo,
ProviderF2FAssessmentId,
ProviderPhoneAssessmentId,
people_id, LastName,FirstName,
SSN,[DOB],[Gender],[Race],[Ethnicity]
into #Patient
FROM #t
--Assessments
SELECT
CallEndDate,
CallEndTime,
DispatchDate,
DispatchTime,
CallDisposition,
DispositionOther,
Notes,
people_id,
ProviderPatientNo,
ProviderF2FAssessmentId,
ProviderPhoneAssessmentId,
AssessmentDate,
case when ArrivalTime is null then '07:00:00' else ArrivalTime end AS [ArrivalTime] ,
ResidentialStatus AS [ResidentialStatus],
County AS [County],
EmploymentStatus AS [EmploymentStatus],
MaritalStatus AS [MaritalStatus],
MilitaryStatus AS [MilitaryStatus],
NumArrests30Days AS [NumArrests30Days],
AttendedSchoolLast3Months AS [AttendedSchoolLast3Months],
EducationLevel AS [EducationLevel],
PrimaryPayorSource AS [PrimaryPayorSource],
SecondaryPayorSource AS [SecondaryPayorSource],
AnnualHouseholdIncome AS [AnnualHouseholdIncome],
NumberInHousehold AS [NumberInHousehold],
CurrentServices AS [CurrentServices],
MHTreatmentDeclaration AS [MHTreatmentDeclaration],
MOTStatus AS [MOTStatus],
DurablePOA AS [DurablePOA],
AssessmentLocation AS [AssessmentLocation],
TransportedByLE AS [TransportedByLE],
TelevideoAssessment AS [TelevideoAssessment],
CurrentDetoxSymptoms AS [CurrentDetoxSymptoms],
HistoryOfDetoxSymptoms AS [HistoryOfDetoxSymptoms],
PrimaryDSMDiagnosis AS [PrimaryDSMDiagnosis],
SecondaryDSMDiagnosis AS [SecondaryDSMDiagnosis],
CompletedByLastName AS [CompletedByLastName],
CompletedByFirstName AS [CompletedByFirstName],
DateDispositionCompleted AS [DateDispositionCompleted],
TimeDispositionCompleted AS [TimeDispositionCompleted],
RecommendedTransportMode AS [RecommendedTransportMode],
DateTransportedToFacility AS [DateTransportedToFacility],
TimeTransportedToFacility AS [TimeTransportedToFacility],
FollowupContacted AS [FollowupContacted],
FollowupReportedServiceHelpful AS [FollowupReportedServiceHelpful],
ContactAttempts AS [ContactAttempts],
VoluntaryAdmissionRecommended AS [VoluntaryAdmissionRecommended],
AdmissionAssessmentViaTelehealth AS [AdmissionAssessmentViaTelehealth],
IsAdmitted AS [IsAdmitted],
FirstHospitalization AS [FirstHospitalization],
PrimaryProblem AS [PrimaryProblem],
IntellectualDisability AS [IntellectualDisability],
MedicalInstability AS [MedicalInstability],
MedicationIssues AS [MedicationIssues],
PastTrauma AS [PastTrauma],
SubstanceAbuse AS [SubstanceAbuse]
into #Assessments
FROM #t
--Drugs
select ProviderF2FAssessmentId,
Drug,
DrugRoute,
DrugFrequency
into #Drugs
from #t
where ProviderF2FAssessmentId is not null
--HospAlternative
select
ProviderF2FAssessmentId,
HospAlternative,
HospAltDisposition
into #HospAlt
from #t
where ProviderF2FAssessmentId is not null
--Hospitalization
select
ProviderF2FAssessmentId,
1 as Hospitalization,
10 as HospitalizationDisposition
into #HospDisp
from #t
where ProviderF2FAssessmentId is not null
/*Create XML*/
declare #output XML
set #output =
--Provider Data
(
SELECT
NPI as [NPI],
FileCreationDate as [FileCreationDate],
cast(FileCreationTime as time) FileCreationTime,
(
--Patient Data
Select
Patient.ProviderPatientNo ,
LastName as [LastName],
FirstName as [FirstName],
SSN as [SSN],
DOB as [DOB],
Gender as [Gender],
Race as [Race],
Ethnicity as [Ethnicity],
--Phone Assessment Data
/*
<ProviderPhoneAssessmentId>52854541</ProviderPhoneAssessmentId>
<CallEndDate>2006-05-04</CallEndDate>
<CallEndTime>01:01:01.001</CallEndTime>
<DispatchDate>2006-05-04</DispatchDate>
<DispatchTime>01:01:01.001</DispatchTime>
<CallDisposition>1</CallDisposition>
<DispositionOther>DispositionOther0</DispositionOther>
<Notes>Notes0</Notes>
*/
(
Select
ProviderPhoneAssessmentId,
CallEndDate,
CallEndTime,
DispatchDate,
DispatchTime,
CallDisposition,
DispositionOther,
Notes
FROM #Assessments
WHERE ProviderPhoneAssessmentId is NOT NULL and ProviderPhoneAssessmentId = Patient.ProviderPhoneAssessmentId
FOR XML PATH(''), ELEMENTS, type) AS [PhoneAssessment/*],
--F2FAssessment
/*
<ProviderF2FAssessmentId>4343</ProviderF2FAssessmentId>
<AssessmentDate>2006-05-04</AssessmentDate>
<ArrivalTime>01:01:01.001</ArrivalTime>
<ResidentialStatus>1</ResidentialStatus>
<County>1</County>
<EmploymentStatus>1</EmploymentStatus>
<MaritalStatus>1</MaritalStatus>
<MilitaryStatus>1</MilitaryStatus>
<NumArrests30Days>50</NumArrests30Days>
<AttendedSchoolLast3Months>1</AttendedSchoolLast3Months>
<EducationLevel>1</EducationLevel>
<PrimaryPayorSource>1</PrimaryPayorSource>
<SecondaryPayorSource>1</SecondaryPayorSource>
<AnnualHouseholdIncome>0</AnnualHouseholdIncome>
<NumberInHousehold>128</NumberInHousehold>
<CurrentServices>1</CurrentServices>
<MHTreatmentDeclaration>1</MHTreatmentDeclaration>
<MOTStatus>1</MOTStatus>
<DurablePOA>1</DurablePOA>
<AssessmentLocation>1</AssessmentLocation>
<TransportedByLE>false</TransportedByLE>
<TelevideoAssessment>false</TelevideoAssessment>
<CurrentDetoxSymptoms>false</CurrentDetoxSymptoms>
<HistoryOfDetoxSymptoms>false</HistoryOfDetoxSymptoms>
<PrimaryDSMDiagnosis>PrimaryDS</PrimaryDSMDiagnosis>
<SecondaryDSMDiagnosis>Secondary</SecondaryDSMDiagnosis>
<CompletedByLastName>CompletedByLastName2</CompletedByLastName>
<CompletedByFirstName>CompletedByFirstName2</CompletedByFirstName>
<DateDispositionCompleted>2006-05-04</DateDispositionCompleted>
<TimeDispositionCompleted>01:01:01.001</TimeDispositionCompleted>
<RecommendedTransportMode>1</RecommendedTransportMode>
<DateTransportedToFacility>2006-05-04</DateTransportedToFacility>
<TimeTransportedToFacility>01:01:01.001</TimeTransportedToFacility>
<FollowupContacted>false</FollowupContacted>
<FollowupReportedServiceHelpful>false</FollowupReportedServiceHelpful>
<ContactAttempts>128</ContactAttempts>
<VoluntaryAdmissionRecommended>false</VoluntaryAdmissionRecommended>
<AdmissionAssessmentViaTelehealth>false</AdmissionAssessmentViaTelehealth>
<IsAdmitted>false</IsAdmitted><FirstHospitalization>1</FirstHospitalization>
<PrimaryProblem>1</PrimaryProblem><IntellectualDisability>1</IntellectualDisability>
<MedicalInstability>1</MedicalInstability>
<MedicationIssues>1</MedicationIssues>
<PastTrauma>1</PastTrauma>
<SubstanceAbuse>1</SubstanceAbuse>
*/
(SELECT
ProviderF2FAssessmentId as [F2FAssessment/ProviderF2FAssessmentId],
AssessmentDate as [F2FAssessment/AssessmentDate],
[ArrivalTime] as [F2FAssessment/ArrivalTime],
ResidentialStatus as [F2FAssessment/ResidentialStatus],
County as [F2FAssessment/County],
EmploymentStatus AS [F2FAssessment/EmploymentStatus],
MaritalStatus AS [F2FAssessment/MaritalStatus],
MilitaryStatus AS [F2FAssessment/MilitaryStatus],
NumArrests30Days AS [F2FAssessment/NumArrests30Days],
AttendedSchoolLast3Months AS [F2FAssessment/AttendedSchoolLast3Months],
EducationLevel AS [F2FAssessment/EducationLevel],
PrimaryPayorSource AS [F2FAssessment/PrimaryPayorSource],
SecondaryPayorSource AS [F2FAssessment/SecondaryPayorSource],
AnnualHouseholdIncome AS [F2FAssessment/AnnualHouseholdIncome],
NumberInHousehold AS [F2FAssessment/NumberInHousehold],
CurrentServices AS [F2FAssessment/CurrentServices],
MHTreatmentDeclaration AS [F2FAssessment/MHTreatmentDeclaration],
MOTStatus AS [F2FAssessment/MOTStatus],
DurablePOA AS [F2FAssessment/DurablePOA],
AssessmentLocation AS [F2FAssessment/AssessmentLocation],
TransportedByLE AS [F2FAssessment/TransportedByLE],
TelevideoAssessment AS [F2FAssessment/TelevideoAssessment],
CurrentDetoxSymptoms AS [F2FAssessment/CurrentDetoxSymptoms],
HistoryOfDetoxSymptoms AS [F2FAssessment/HistoryOfDetoxSymptoms],
PrimaryDSMDiagnosis AS [F2FAssessment/PrimaryDSMDiagnosis],
SecondaryDSMDiagnosis AS [F2FAssessment/SecondaryDSMDiagnosis],
CompletedByLastName AS [F2FAssessment/CompletedByLastName],
CompletedByFirstName AS [F2FAssessment/CompletedByFirstName],
DateDispositionCompleted AS [F2FAssessment/DateDispositionCompleted],
TimeDispositionCompleted AS [F2FAssessment/TimeDispositionCompleted],
RecommendedTransportMode AS [F2FAssessment/RecommendedTransportMode],
ISNULL(CAST(DateTransportedToFacility as varchar(30)),'xsi:nil="true"') AS [F2FAssessment/DateTransportedToFacility],
ISNULL(CAST(TimeTransportedToFacility as varchar(30)),'xsi:nil="true"')AS [F2FAssessment/TimeTransportedToFacility],
FollowupContacted AS [F2FAssessment/FollowupContacted],
FollowupReportedServiceHelpful AS [F2FAssessment/FollowupReportedServiceHelpful],
ContactAttempts AS [F2FAssessment/ContactAttempts],
VoluntaryAdmissionRecommended AS [F2FAssessment/VoluntaryAdmissionRecommended],
AdmissionAssessmentViaTelehealth AS [F2FAssessment/AdmissionAssessmentViaTelehealth],
IsAdmitted AS [F2FAssessment/IsAdmitted],
FirstHospitalization AS [F2FAssessment/FirstHospitalization],
PrimaryProblem AS [F2FAssessment/PrimaryProblem],
IntellectualDisability AS [F2FAssessment/IntellectualDisability],
MedicalInstability AS [F2FAssessment/MedicalInstability],
MedicationIssues AS [F2FAssessment/MedicationIssues],
PastTrauma AS [F2FAssessment/PastTrauma],
SubstanceAbuse AS [F2FAssessment/SubstanceAbuse]
,
(
SELECT
ISNULL(Drug,'') as Drug,
DrugRoute,
DrugFrequency
From #Drugs drugs
Where drugs.Drug is NOT NULL and drugs.ProviderF2FAssessmentId = #Assessments.ProviderF2FAssessmentId
FOR XML PATH(''), type) AS [F2FAssessment/F2FDrug]
,
(
SELECT
HospAlternative,
HospAltDisposition
From #HospAlt HospAlt
Where HospAlt.ProviderF2FAssessmentId = #Assessments.ProviderF2FAssessmentId
FOR XML PATH(''), type) AS [F2FAssessment/F2FHospAlternative]
,
(
SELECT
Hospitalization,
HospitalizationDisposition
From #HospDisp HospDisp
Where HospDisp.ProviderF2FAssessmentId = #Assessments.ProviderF2FAssessmentId
FOR XML PATH(''), type) AS [F2FAssessment/F2FHospitalization]
FROM #Assessments
Where ProviderF2FAssessmentId IS NOT NULL and ProviderF2FAssessmentId = Patient.ProviderF2FAssessmentId
FOR XML PATH(''), ELEMENTS, type) AS [*]
FROM #Patient Patient
FOR XML PATH('Patient'), type
)
from #t
group by NPI,FileCreationDate, FileCreationTime
for xml path('')
)
; with xmlnamespaces ('http://www.tn.gov/mental/Schemas/CrisisAssessment' AS "xsd", 'http://www.w3.org/2001/XMLSchema-instance' as "xsi")
select #output FOR XML PATH(''),TYPE, ROOT('Provider')
Here is an example of the XML output that I am currently getting:
<Provider xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.tn.gov/mental/Schemas/CrisisAssessment">
<NPI>1306875695</NPI>
<FileCreationDate>2014-02-12</FileCreationDate>
<FileCreationTime>15:19:37</FileCreationTime>
<Patient>
<ProviderPatientNo>108677</ProviderPatientNo>
<LastName>David</LastName>
<FirstName>Joe</FirstName>
<SSN>414555555</SSN>
<DOB>1999-01-23</DOB>
<Gender>2</Gender>
<Race>1</Race>
<Ethnicity>2</Ethnicity>
<PhoneAssessment>
<ProviderPhoneAssessmentId>59DC25C9-B659-42A3-B43D-26C741F9B929</ProviderPhoneAssessmentId>
<CallEndDate>2013-09-26</CallEndDate>
<CallEndTime>15:17:00</CallEndTime>
<CallDisposition>1</CallDisposition>
</PhoneAssessment>
</Patient>
<Patient>
<ProviderPatientNo>108677</ProviderPatientNo>
<LastName>David</LastName>
<FirstName>Joe</FirstName>
<SSN>414555555</SSN>
<DOB>1999-01-23</DOB>
<Gender>2</Gender>
<Race>1</Race>
<Ethnicity>2</Ethnicity>
<F2FAssessment>
<ProviderF2FAssessmentId>35159D47-32B2-445C-A905-019E191FDDE2</ProviderF2FAssessmentId>
<AssessmentDate>2013-09-25</AssessmentDate>
<ArrivalTime>19:22:00</ArrivalTime>
<ResidentialStatus>13</ResidentialStatus>
<County>47</County>
<EmploymentStatus>12</EmploymentStatus>
<MaritalStatus>6</MaritalStatus>
<MilitaryStatus>4</MilitaryStatus>
<AttendedSchoolLast3Months>3</AttendedSchoolLast3Months>
<EducationLevel>23</EducationLevel>
<PrimaryPayorSource>8</PrimaryPayorSource>
<SecondaryPayorSource>9</SecondaryPayorSource>
<AnnualHouseholdIncome>0</AnnualHouseholdIncome>
<NumberInHousehold>4</NumberInHousehold>
<CurrentServices>8</CurrentServices>
<MHTreatmentDeclaration>3</MHTreatmentDeclaration>
<MOTStatus>3</MOTStatus>
<DurablePOA>3</DurablePOA>
<AssessmentLocation>4</AssessmentLocation>
<TransportedByLE>0</TransportedByLE>
<TelevideoAssessment>0</TelevideoAssessment>
<CurrentDetoxSymptoms>0</CurrentDetoxSymptoms>
<HistoryOfDetoxSymptoms>0</HistoryOfDetoxSymptoms>
<PrimaryDSMDiagnosis>V71.09 </PrimaryDSMDiagnosis>
<SecondaryDSMDiagnosis>V71.09</SecondaryDSMDiagnosis>
<CompletedByLastName>Tweed</CompletedByLastName>
<CompletedByFirstName>A</CompletedByFirstName>
<DateDispositionCompleted>2013-09-25</DateDispositionCompleted>
<TimeDispositionCompleted>21:10:51</TimeDispositionCompleted>
<RecommendedTransportMode>3</RecommendedTransportMode>
<DateTransportedToFacility>xsi:nil="true"</DateTransportedToFacility>
<TimeTransportedToFacility>xsi:nil="true"</TimeTransportedToFacility>
<FollowupContacted>1</FollowupContacted>
<FollowupReportedServiceHelpful>1</FollowupReportedServiceHelpful>
<VoluntaryAdmissionRecommended>0</VoluntaryAdmissionRecommended>
<AdmissionAssessmentViaTelehealth>0</AdmissionAssessmentViaTelehealth>
<IsAdmitted>0</IsAdmitted>
<PrimaryProblem>2</PrimaryProblem>
<IntellectualDisability>3</IntellectualDisability>
<MedicalInstability>3</MedicalInstability>
<MedicationIssues>3</MedicationIssues>
<PastTrauma>3</PastTrauma>
<SubstanceAbuse>2</SubstanceAbuse>
<F2FHospAlternative>
<HospAlternative>8</HospAlternative>
<HospAltDisposition>4</HospAltDisposition>
</F2FHospAlternative>
<F2FHospitalization>
<Hospitalization>1</Hospitalization>
<HospitalizationDisposition>10</HospitalizationDisposition>
</F2FHospitalization>
</F2FAssessment>
</Patient>
</Provider>
Here is an example of how I need it to look:
<Provider xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.tn.gov/mental/Schemas/CrisisAssessment">
<NPI>1306875695</NPI>
<FileCreationDate>2014-02-12</FileCreationDate>
<FileCreationTime>15:19:37</FileCreationTime>
<Patient>
<ProviderPatientNo>108677</ProviderPatientNo>
<LastName>David</LastName>
<FirstName>Joe</FirstName>
<SSN>414555555</SSN>
<DOB>1999-01-23</DOB>
<Gender>2</Gender>
<Race>1</Race>
<Ethnicity>2</Ethnicity>
<PhoneAssessment>
<ProviderPhoneAssessmentId>59DC25C9-B659-42A3-B43D-26C741F9B929</ProviderPhoneAssessmentId>
<CallEndDate>2013-09-26</CallEndDate>
<CallEndTime>15:17:00</CallEndTime>
<CallDisposition>1</CallDisposition>
</PhoneAssessment>
<F2FAssessment>
<ProviderF2FAssessmentId>35159D47-32B2-445C-A905-019E191FDDE2</ProviderF2FAssessmentId>
<AssessmentDate>2013-09-25</AssessmentDate>
<ArrivalTime>19:22:00</ArrivalTime>
<ResidentialStatus>13</ResidentialStatus>
<County>47</County>
<EmploymentStatus>12</EmploymentStatus>
<MaritalStatus>6</MaritalStatus>
<MilitaryStatus>4</MilitaryStatus>
<AttendedSchoolLast3Months>3</AttendedSchoolLast3Months>
<EducationLevel>23</EducationLevel>
<PrimaryPayorSource>8</PrimaryPayorSource>
<SecondaryPayorSource>9</SecondaryPayorSource>
<AnnualHouseholdIncome>0</AnnualHouseholdIncome>
<NumberInHousehold>4</NumberInHousehold>
<CurrentServices>8</CurrentServices>
<MHTreatmentDeclaration>3</MHTreatmentDeclaration>
<MOTStatus>3</MOTStatus>
<DurablePOA>3</DurablePOA>
<AssessmentLocation>4</AssessmentLocation>
<TransportedByLE>0</TransportedByLE>
<TelevideoAssessment>0</TelevideoAssessment>
<CurrentDetoxSymptoms>0</CurrentDetoxSymptoms>
<HistoryOfDetoxSymptoms>0</HistoryOfDetoxSymptoms>
<PrimaryDSMDiagnosis>V71.09 </PrimaryDSMDiagnosis>
<SecondaryDSMDiagnosis>V71.09</SecondaryDSMDiagnosis>
<CompletedByLastName>Tweed</CompletedByLastName>
<CompletedByFirstName>A</CompletedByFirstName>
<DateDispositionCompleted>2013-09-25</DateDispositionCompleted>
<TimeDispositionCompleted>21:10:51</TimeDispositionCompleted>
<RecommendedTransportMode>3</RecommendedTransportMode>
<DateTransportedToFacility>xsi:nil="true"</DateTransportedToFacility>
<TimeTransportedToFacility>xsi:nil="true"</TimeTransportedToFacility>
<FollowupContacted>1</FollowupContacted>
<FollowupReportedServiceHelpful>1</FollowupReportedServiceHelpful>
<VoluntaryAdmissionRecommended>0</VoluntaryAdmissionRecommended>
<AdmissionAssessmentViaTelehealth>0</AdmissionAssessmentViaTelehealth>
<IsAdmitted>0</IsAdmitted>
<PrimaryProblem>2</PrimaryProblem>
<IntellectualDisability>3</IntellectualDisability>
<MedicalInstability>3</MedicalInstability>
<MedicationIssues>3</MedicationIssues>
<PastTrauma>3</PastTrauma>
<SubstanceAbuse>2</SubstanceAbuse>
<F2FHospAlternative>
<HospAlternative>8</HospAlternative>
<HospAltDisposition>4</HospAltDisposition>
</F2FHospAlternative>
<F2FHospitalization>
<Hospitalization>1</Hospitalization>
<HospitalizationDisposition>10</HospitalizationDisposition>
</F2FHospitalization>
</F2FAssessment>
</Patient>
</Provider>
Any help you can offer would be greatly appreciated.
This is working as I'll show in my test code. However, the one problem we have is that if someone has both a F2FAssessment and a PhoneAssessment it will generate multiple tags.
This happen because you insert the person record 2 times.
first insert: Person data + phoneAssesment data
second insert: Peson data + F2FAssessment
Table t has 2 records for person with NPI:1306875695
my suggestion is to modify the #t table,
Create #temp1 table, the #temp1 should only have person data + phoneAssesment
Create #temp2 table, the #temp2 only contain PersonID + F2FAssessment (PErsonId act as foreign key)
Insert the data, to both table.
Inner Join both table #temp1 and #temp2 as Table #t. Use the PersonId as the join condition.
Now table #t will have only 1 record for NPI: 1306875695
Try this suggestion, Hope this is help.
If you only want one Patient element, make the PhoneAssessment and F2F* statements sub queries:
WITH XMLNAMESPACES (DEFAULT 'http://www.tn.gov/mental/Schemas/CrisisAssessment')
SELECT
[NPI],
[FileCreationDate],
[FileCreationTime],
(
SELECT
ProviderPatientNo,
LastName, FirstName,
SSN, DOB, Gender,
Race, Ethnicity,
(
SELECT
ProviderPhoneAssessmentId, CallEndDate, CallEndTime, CallDisposition
FROM #t pa
WHERE ProviderPhoneAssessmentId is not null
and pa.ProviderPatientNo = p.ProviderPatientNo
FOR XML PATH('PhoneAssesment'), TYPE, ELEMENTS XSINIL
),
(
SELECT
ProviderF2FAssessmentId,
AssessmentDate, ArrivalTime, ResidentialStatus, County, EmploymentStatus,
MaritalStatus, MilitaryStatus, AttendedSchoolLast3Months, EducationLevel,
PrimaryPayorSource, SecondaryPayorSource, AnnualHouseholdIncome,
NumberInHousehold, CurrentServices, MHTreatmentDeclaration, MOTStatus,
DurablePOA, AssessmentLocation, TransportedByLE, TelevideoAssessment,
CurrentDetoxSymptoms, HistoryOfDetoxSymptoms, PrimaryDSMDiagnosis,
SecondaryDSMDiagnosis, CompletedByLastName, CompletedByFirstName,
DateDispositionCompleted, TimeDispositionCompleted, RecommendedTransportMode,
DateTransportedToFacility, TimeTransportedToFacility, FollowupContacted,
FollowupReportedServiceHelpful, VoluntaryAdmissionRecommended,
AdmissionAssessmentViaTelehealth, IsAdmitted, PrimaryProblem,
IntellectualDisability, MedicalInstability, MedicationIssues, PastTrauma,
SubstanceAbuse,
HospAlternative as [F2FHospAlternative/HospAlternative],
HospAltDisposition as [F2FHospAlternative/HospAltDisposition],
Hospitalization as [F2FHospitalization/Hospitalization],
HospitalizationDisposition as [F2FHospitalization/HospitalizationDisposition]
FROM #t f2f
WHERE f2f.ProviderF2FAssessmentId is not null
and f2f.ProviderPatientNo = p.ProviderPatientNo
GROUP BY ProviderF2FAssessmentId,
AssessmentDate, ArrivalTime, ResidentialStatus, County, EmploymentStatus,
MaritalStatus, MilitaryStatus, AttendedSchoolLast3Months, EducationLevel,
PrimaryPayorSource, SecondaryPayorSource, AnnualHouseholdIncome,
NumberInHousehold, CurrentServices, MHTreatmentDeclaration, MOTStatus,
DurablePOA, AssessmentLocation, TransportedByLE, TelevideoAssessment,
CurrentDetoxSymptoms, HistoryOfDetoxSymptoms, PrimaryDSMDiagnosis,
SecondaryDSMDiagnosis, CompletedByLastName, CompletedByFirstName,
DateDispositionCompleted, TimeDispositionCompleted, RecommendedTransportMode,
DateTransportedToFacility, TimeTransportedToFacility, FollowupContacted,
FollowupReportedServiceHelpful, VoluntaryAdmissionRecommended,
AdmissionAssessmentViaTelehealth, IsAdmitted, PrimaryProblem,
IntellectualDisability, MedicalInstability, MedicationIssues, PastTrauma,
SubstanceAbuse, HospAlternative, HospAltDisposition, Hospitalization,
HospitalizationDisposition
FOR XML PATH('F2FAssessment'), TYPE, ELEMENTS XSINIL
)
FROM #t p
GROUP BY ProviderPatientNo, LastName, FirstName, SSN, DOB, Gender, Race, Ethnicity
FOR XML PATH('Patient'), TYPE, ELEMENTS XSINIL
)
FROM (SELECT TOP(1) [NPI], [FileCreationDate], [FileCreationTime] FROM #t) as FileHeader
FOR XML PATH('Provider'), ELEMENTS XSINIL
Also, I am guessing you want xsi:nil="true" to be an attribute. That is achieved through the XSINIL option. Also, you reference a namespace, but do not use it. Do you mean to make it the default (WITH XMLNAMESPACES (DEFAULT 'http://www.tn.gov/mental/Schemas/CrisisAssessment'))?
Produces:
<Provider xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.tn.gov/mental/Schemas/CrisisAssessment">
<NPI>1306875695</NPI>
<FileCreationDate>2014-02-12</FileCreationDate>
<FileCreationTime>15:19:37</FileCreationTime>
<Patient xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.tn.gov/mental/Schemas/CrisisAssessment">
<ProviderPatientNo>108677</ProviderPatientNo>
<LastName>David</LastName>
<FirstName>Joe</FirstName>
<SSN>414555555</SSN>
<DOB>1999-01-23</DOB>
<Gender>2</Gender>
<Race>1</Race>
<Ethnicity>2</Ethnicity>
<PhoneAssesment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.tn.gov/mental/Schemas/CrisisAssessment">
<ProviderPhoneAssessmentId>59DC25C9-B659-42A3-B43D-26C741F9B929</ProviderPhoneAssessmentId>
<CallEndDate>2013-09-26</CallEndDate>
<CallEndTime>15:17:00</CallEndTime>
<CallDisposition>1</CallDisposition>
</PhoneAssesment>
<F2FAssessment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.tn.gov/mental/Schemas/CrisisAssessment">
<ProviderF2FAssessmentId>35159D47-32B2-445C-A905-019E191FDDE2</ProviderF2FAssessmentId>
<AssessmentDate>2013-09-25</AssessmentDate>
<ArrivalTime>19:22:00</ArrivalTime>
<ResidentialStatus>13</ResidentialStatus>
<County>47</County>
<EmploymentStatus>12</EmploymentStatus>
<MaritalStatus>6</MaritalStatus>
<MilitaryStatus>4</MilitaryStatus>
<AttendedSchoolLast3Months>3</AttendedSchoolLast3Months>
<EducationLevel>23</EducationLevel>
<PrimaryPayorSource>8</PrimaryPayorSource>
<SecondaryPayorSource>9</SecondaryPayorSource>
<AnnualHouseholdIncome>0</AnnualHouseholdIncome>
<NumberInHousehold>4</NumberInHousehold>
<CurrentServices>8</CurrentServices>
<MHTreatmentDeclaration>3</MHTreatmentDeclaration>
<MOTStatus>3</MOTStatus>
<DurablePOA>3</DurablePOA>
<AssessmentLocation>4</AssessmentLocation>
<TransportedByLE>0</TransportedByLE>
<TelevideoAssessment>0</TelevideoAssessment>
<CurrentDetoxSymptoms>0</CurrentDetoxSymptoms>
<HistoryOfDetoxSymptoms>0</HistoryOfDetoxSymptoms>
<PrimaryDSMDiagnosis>V71.09 </PrimaryDSMDiagnosis>
<SecondaryDSMDiagnosis>V71.09</SecondaryDSMDiagnosis>
<CompletedByLastName>Tweed</CompletedByLastName>
<CompletedByFirstName>A</CompletedByFirstName>
<DateDispositionCompleted>2013-09-25</DateDispositionCompleted>
<TimeDispositionCompleted>21:10:51</TimeDispositionCompleted>
<RecommendedTransportMode>3</RecommendedTransportMode>
<DateTransportedToFacility xsi:nil="true" />
<TimeTransportedToFacility xsi:nil="true" />
<FollowupContacted>1</FollowupContacted>
<FollowupReportedServiceHelpful>1</FollowupReportedServiceHelpful>
<VoluntaryAdmissionRecommended>0</VoluntaryAdmissionRecommended>
<AdmissionAssessmentViaTelehealth>0</AdmissionAssessmentViaTelehealth>
<IsAdmitted>0</IsAdmitted>
<PrimaryProblem>2</PrimaryProblem>
<IntellectualDisability>3</IntellectualDisability>
<MedicalInstability>3</MedicalInstability>
<MedicationIssues>3</MedicationIssues>
<PastTrauma>3</PastTrauma>
<SubstanceAbuse>2</SubstanceAbuse>
<F2FHospAlternative>
<HospAlternative>8</HospAlternative>
<HospAltDisposition>4</HospAltDisposition>
</F2FHospAlternative>
<F2FHospitalization>
<Hospitalization xsi:nil="true" />
<HospitalizationDisposition xsi:nil="true" />
</F2FHospitalization>
</F2FAssessment>
</Patient>
</Provider>