· 9 years ago · Jan 30, 2017, 11:14 AM
1-- object name : RPTSalesOrderProc (Stored Procedure)
2-- created on : 15/11/2012 14:26:42
3-- scripted on : 30/01/2017 11:12:39
4-- using server: FRSNETDEV
5-- and database: Dev
6
7SET QUOTED_IDENTIFIER ON
8GO
9SET ANSI_NULLS ON
10GO
11
12if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RPTSalesOrderProc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
13 return
14exec('create procedure [RPTSalesOrderProc] as')
15GO
16
17
18ALTER PROCEDURE [dbo].[RPTSalesOrderProc] (@SO int) AS
19
20CREATE TABLE #tmp (
21[Sales Order Number] INT,
22[Internal Order Number] INT,
23[Stock Detail Number] INT,
24[Order Pad Number] NVARCHAR(20),
25[Sales Order Date] DATETIME,
26[Date Required] DATETIME,
27[Sales Person 1] NVARCHAR(30),
28[Sales Person 2] NVARCHAR(30),
29[Main Address 1] NVARCHAR(30),
30[Main Address 2] NVARCHAR(30),
31[Main Address 3] NVARCHAR(30),
32[Main Address 4] NVARCHAR(30),
33[Main Address 5] NVARCHAR(30),
34[Main Address 6] NVARCHAR(50),
35[Main Address Postcode] NVARCHAR(10),
36[SKU Code] NVARCHAR(30),
37[Product Class] INT,
38[Product Range] NVARCHAR(30),
39[Model Number] NVARCHAR(80),
40[Product Description 1] NVARCHAR(80),
41[Product Description 2] NVARCHAR(80),
42[Product Description 3] NVARCHAR(80),
43[Option Code] NVARCHAR(512),
44Quantity DECIMAL(12,4),
45[MRP Price] MONEY,
46[Original Selling Price] MONEY,
47[Discounted Selling Price] MONEY,
48[Final Selling Price] MONEY,
49VAT MONEY,
50[Supplier Name] NVARCHAR(30),
51[Sales Order Total] MONEY,
52[Customer Title] NVARCHAR(10),
53[Customer Initials] NVARCHAR(20),
54[Customer Name] NVARCHAR(50),
55[Customer Account] INT,
56[Flat Number] NVARCHAR(30),
57[House Number] NVARCHAR(10),
58[House Name] NVARCHAR(30),
59[Approved Finance] MONEY,
60[Unapproved Finance] MONEY,
61[Sales Order Complete] BIT,
62[Sales Order Cancelled] BIT,
63[Sales Order Delivered] BIT,
64[Sales Order Printed] BIT,
65[Sales Order Comments] NVARCHAR(200),
66[Delivery House Number] NVARCHAR(10),
67[Delivery House Name] NVARCHAR(30),
68[Delivery Flat Number] NVARCHAR(30),
69[Delivery Address 1] NVARCHAR(30),
70[Delivery Address 2] NVARCHAR(30),
71[Delivery Address 3] NVARCHAR(30),
72[Delivery Address 4] NVARCHAR(30),
73[Delivery Address 5] NVARCHAR(30),
74[Delivery Address 6] NVARCHAR(50),
75[Delivery Address Postcode] NVARCHAR(10),
76[Delivery Address Instruction] NVARCHAR(200),
77[Main Address Instruction] NVARCHAR(200),
78Quotation BIT,
79Imperfect BIT,
80[On Hold] BIT,
81[On Demand] BIT,
82[On Order] BIT,
83[On Hand] BIT,
84[Delivery Method] INT,
85[Delivery Branch] NVARCHAR(50),
86[Order Amendment Number] INT,
87[Accept Part Delivery] BIT,
88[Accept Early Delivery] BIT,
89[Quote Expiry] DATETIME,
90[Line Discount Price] MONEY,
91[Customer Telephone] NVARCHAR(30),
92[Customer Daytime] NVARCHAR(30),
93[Customer Mobile] NVARCHAR(30),
94[Hide SO Lines] BIT,
95[Lead Time] INT,
96[Selling Branch Name] NVARCHAR(50),
97[Selling Branch Address 1] NVARCHAR(50),
98[Selling Branch Address 2] NVARCHAR(50),
99[Selling Branch Address 3] NVARCHAR(50),
100[Selling Branch Address 4] NVARCHAR(50),
101[Selling Branch Address 5] NVARCHAR(50),
102[Selling Branch Address 6] NVARCHAR(50),
103[Selling Branch Postcode] NVARCHAR(10),
104[Selling Branch Telephone] NVARCHAR(50),
105[Selling Branch Fax] NVARCHAR(50),
106[Product Group] NVARCHAR(50),
107[Print Line Prices] BIT,
108ActualWidth DECIMAL(18,4),
109Remnant BIT,
110DeliveryDate DATETIME,
111DeliveryConfirmed BIT,
112DeliveryActive BIT,
113[Customer Email] NVARCHAR(100),
114DeliveryDueAfter DATETIME,
115RangeCaveatText NVARCHAR(500),
116ItemCaveatText NVARCHAR(500),
117IsTaxInclusivePrice BIT,
118SetParentID INT,
119Markdown MONEY,
120VatRate DECIMAL(12,8),
121CompanyName NVARCHAR(50),
122UnfinancedPayments MONEY,
123TaxFreeSellingApplied BIT,
124OriginalVATAmount MONEY,
125LineDiscountedVATAmount MONEY,
126LineTotalPrice MONEY,
127MarkDownReason NVARCHAR(100),
128StdVATCode INT,
129StdVATRate DECIMAL(12,4),
130StdVATDesc NVARCHAR(100),
131LineVATCode INT,
132LineVATDesc NVARCHAR(100),
133SetPrice MONEY,
134IsSetHeader BIT,
135SuperCalculatedVatRate DECIMAL(18,8)
136)
137
138 DECLARE @COPY int
139 DECLARE @ShowSetHeader BIT
140 DECLARE @SalesPerson1 NVARCHAR(30), @SalesPerson2 NVARCHAR(30), @MainAddress1 NVARCHAR(30), @MainAddress2 NVARCHAR(30), @MainAddress3 NVARCHAR(30),
141 @MainAddress4 NVARCHAR(30), @MainAddress5 NVARCHAR(30), @MainAddress6 NVARCHAR(50), @MainAddressPostcode NVARCHAR(10), @SalesOrderTotal MONEY,
142 @CustomerTitle NVARCHAR(10), @CustomerInitials NVARCHAR(20), @CustomerName NVARCHAR(50), @CustomerAccount INT, @FlatNumber NVARCHAR(30), @HouseNumber NVARCHAR(10),
143 @HouseName NVARCHAR(30), @ApprovedFinance MONEY, @UnapprovedFinance MONEY, @DeliveryHouseNumber NVARCHAR(10), @DeliveryHouseName NVARCHAR(30),
144 @DeliveryFlatNumber NVARCHAR(30), @DeliveryAddress1 NVARCHAR(30), @DeliveryAddress2 NVARCHAR(30), @DeliveryAddress3 NVARCHAR(30), @DeliveryAddress4 NVARCHAR(30), @DeliveryAddress5 NVARCHAR(30),
145 @DeliveryAddress6 NVARCHAR(50), @DeliveryAddressPostcode NVARCHAR(10), @DeliveryAddressInstruction NVARCHAR(200), @MainAddressInstruction NVARCHAR(200), @DeliveryBranch NVARCHAR(50),
146 @CustomerTelephone NVARCHAR(30), @CustomerDaytime NVARCHAR(30), @CustomerMobile NVARCHAR(30), @SellingBranchName NVARCHAR(50), @SellingBranchAddress1 NVARCHAR(50), @SellingBranchAddress2 NVARCHAR(50),
147 @SellingBranchAddress3 NVARCHAR(50), @SellingBranchAddress4 NVARCHAR(50), @SellingBranchAddress5 NVARCHAR(50), @SellingBranchAddress6 NVARCHAR(50), @SellingBranchPostcode NVARCHAR(50),
148 @SellingBranchTelephone NVARCHAR(50), @SellingBranchFax NVARCHAR(50), @RangeCaveatText NVARCHAR(1000), @ItemCaveatText NVARCHAR(1000), @IsTaxInclusivePrice BIT, @CustomerEmail NVARCHAR(100), @ImagePath NVARCHAR(200), @SocialPath NVARCHAR(200),
149 @AnyItemMarkedDown BIT, @HideModelNo BIT, @CompanyID INT, @ShowSetDetails BIT, @ShowLineDiscounts NVARCHAR(1), @ShowImperfectNotes NVARCHAR(1), @ShowMarkdownReasons NVARCHAR(1),
150 @StdVATCode INT, @StdVATRate DECIMAL(12,4), @StdVATDesc NVARCHAR(100), @LineVATCode INT, @LineVATDesc NVARCHAR(100),@Imperfect BIT
151 SELECT
152 @COPY = dbo.GetAppPar('SOA_Copies', loc.CompanyID, 0),
153 @HideModelNo = ISNULL(dbo.GetBitAppPar('SOA_HIDE_MODEL_NO', loc.CompanyID, 0), 0),
154 @ImagePath = RTRIM(dbo.GetAppPar('IMAGE_FOLDER_PATH', loc.CompanyID, 0)) + ISNULL(loc.LogoImageName, 'Logo.jpg'),
155 @SocialPath = RTRIM(dbo.GetAppPar('SOA_SOCIAL_MEDIA_IMAGE_PATH', loc.CompanyID, 0)),
156 @ShowSetHeader = ISNULL(dbo.GetBitAppPar('SO_SET_VIEW', loc.CompanyID, 0), 0),
157 @CompanyID = loc.CompanyID,
158 @ShowSetDetails = ISNULL(dbo.GetBitAppPar('SO_SHOW_SET_DETAIL', loc.CompanyID, 0), 0),
159 @ShowLineDiscounts = ISNULL(dbo.GetBitAppParAsYN('SOA_SHOW_LINE_DISCOUNTS', loc.CompanyID, 0), 0),
160 @ShowImperfectNotes = ISNULL(dbo.GetBitAppParAsYN('SOA_SHOW_IMPERFECT_NOTES', loc.CompanyID, 0), 0),
161 @ShowMarkdownReasons = ISNULL(dbo.GetBitAppParAsYN('SOA_SHOW_MARKDOWN_REASONS', loc.CompanyID, 0), 0)
162 FROM SalesOrder so
163 JOIN Location loc ON loc.LocationID = so.OrderBranch
164 WHERE so.SalesOrderID = @SO
165
166 IF @ShowSetDetails = 0
167 SET @ShowSetHeader = 1
168
169 INSERT INTO #tmp
170 SELECT *, NULL, 0,
171 CASE WHEN ([Final Selling Price]-(VAT * Quantity)) = 0 THEN 0 ELSE convert(decimal(18,8),(VAT * Quantity))/([Final Selling Price]-(VAT * Quantity)) END
172 FROM dbo.RPTSalesOrder
173 WHERE dbo.RPTSalesOrder.[Sales Order Number]=@SO
174
175 IF @ShowSetHeader = 1
176 BEGIN
177
178 DECLARE @IsTaxInclusive BIT, @SPID INT, @SetPrice MONEY
179
180 SELECT @IsTaxInclusive = loc.IsTaxInclusivePrice
181 FROM SalesOrder so
182 JOIN Location loc ON so.OrderBranch = loc.LocationID
183 WHERE so.SalesOrderID = @SO
184
185 DECLARE c2 CURSOR FOR
186 SELECT SetParentID,
187 CASE WHEN @IsTaxInclusive = 1 THEN
188 Sum([Line Discount Price])
189 ELSE
190 Sum([Line Discount Price] - (LineDiscountedVATAmount * Quantity))
191 --Sum([Line Discount Price] - (VAT * Quantity))
192 END,
193 MAX([Sales Person 1]), MAX([Sales Person 2]), MAX([Main Address 1]), MAX([Main Address 2]), MAX([Main Address 3]),
194 MAX([Main Address 4]), MAX([Main Address 5]), MAX([Main Address 6]), MAX([Main Address Postcode]), MAX([Sales Order Total]),
195 MAX([Customer Title]), MAX([Customer Initials]), MAX([Customer Name]), MAX([Customer Account]), MAX([Flat Number]), MAX([House Number]),
196 MAX([House Name]), MAX([Approved Finance]), MAX([Unapproved Finance]), MAX([Delivery House Number]), MAX([Delivery House Name]),
197 MAX([Delivery Flat Number]), MAX([Delivery Address 1]), MAX([Delivery Address 2]), MAX([Delivery Address 3]), MAX([Delivery Address 4]), MAX([Delivery Address 5]),
198 MAX([Delivery Address 6]), MAX([Delivery Address Postcode]), MAX([Delivery Address Instruction]), MAX([Main Address Instruction]), MAX([Delivery Branch]),
199 MAX([Customer Telephone]), MAX([Customer Daytime]), MAX([Customer Mobile]), MAX([Selling Branch Name]),MAX([Selling Branch Address 1]), MAX([Selling Branch Address 2]),
200 MAX([Selling Branch Address 3]), MAX([Selling Branch Address 4]), MAX([Selling Branch Address 5]), MAX([Selling Branch Address 6]), MAX([Selling Branch Postcode]),
201 MAX([Selling Branch Telephone]), MAX([Selling Branch Fax]), MAX(RangeCaveatText), MAX(ItemCaveatText), CONVERT(BIT, MAX(CONVERT(INT, IsTaxInclusivePrice))), MAX([Customer Email])
202 FROM #tmp WHERE SetParentID IS NOT NULL GROUP BY SetParentID
203
204 OPEN c2
205
206 FETCH c2 INTO @SPID, @SetPrice, @SalesPerson1, @SalesPerson2, @MainAddress1, @MainAddress2, @MainAddress3,
207 @MainAddress4, @MainAddress5, @MainAddress6, @MainAddressPostcode, @SalesOrderTotal,
208 @CustomerTitle, @CustomerInitials, @CustomerName, @CustomerAccount, @FlatNumber, @HouseNumber,
209 @HouseName, @ApprovedFinance, @UnapprovedFinance, @DeliveryHouseNumber, @DeliveryHouseName,
210 @DeliveryFlatNumber, @DeliveryAddress1, @DeliveryAddress2, @DeliveryAddress3, @DeliveryAddress4, @DeliveryAddress5,
211 @DeliveryAddress6, @DeliveryAddressPostcode, @DeliveryAddressInstruction, @MainAddressInstruction, @DeliveryBranch,
212 @CustomerTelephone, @CustomerDaytime, @CustomerMobile, @SellingBranchName, @SellingBranchAddress1, @SellingBranchAddress2,
213 @SellingBranchAddress3, @SellingBranchAddress4, @SellingBranchAddress5, @SellingBranchAddress6, @SellingBranchPostcode,
214 @SellingBranchTelephone, @SellingBranchFax, @RangeCaveatText, @ItemCaveatText, @IsTaxInclusivePrice, @CustomerEmail
215
216 WHILE @@FETCH_STATUS = 0
217 BEGIN
218
219 INSERT INTO #tmp (
220 [Sales Order Number], [Internal Order Number], [Stock Detail Number], [Order Pad Number],
221 [Sales Order Date], [Date Required], [Sales Person 1], [Sales Person 2],
222 [Main Address 1], [Main Address 2], [Main Address 3], [Main Address 4],
223 [Main Address 5], [Main Address 6], [Main Address Postcode], [SKU Code],
224 [Product Class], [Product Range], [Model Number], [Product Description 1],
225 [Product Description 2], [Product Description 3], [Option Code], Quantity,
226 [MRP Price], [Original Selling Price], [Discounted Selling Price], [Final Selling Price],
227 VAT, [Supplier Name], [Sales Order Total], [Customer Title],
228 [Customer Initials], [Customer Name], [Customer Account], [Flat Number],
229 [House Number], [House Name], [Approved Finance], [Unapproved Finance],
230 [Sales Order Complete], [Sales Order Cancelled], [Sales Order Delivered], [Sales Order Printed],
231 [Sales Order Comments], [Delivery House Number], [Delivery House Name], [Delivery Flat Number],
232 [Delivery Address 1], [Delivery Address 2], [Delivery Address 3], [Delivery Address 4],
233 [Delivery Address 5], [Delivery Address 6], [Delivery Address Postcode], [Delivery Address Instruction],
234 [Main Address Instruction], Quotation, Imperfect, [On Hold], [On Demand],
235 [On Order], [On Hand], [Delivery Method], [Delivery Branch],
236 [Order Amendment Number], [Accept Part Delivery], [Accept Early Delivery], [Quote Expiry],
237 [Line Discount Price], [Customer Telephone], [Customer Daytime], [Customer Mobile],
238 [Hide SO Lines], [Lead Time], [Selling Branch Name], [Selling Branch Address 1],
239 [Selling Branch Address 2], [Selling Branch Address 3], [Selling Branch Address 4], [Selling Branch Address 5],
240 [Selling Branch Address 6], [Selling Branch Postcode], [Selling Branch Telephone], [Selling Branch Fax],
241 [Product Group], [Print Line Prices], ActualWidth, Remnant,
242 DeliveryDate, DeliveryConfirmed, DeliveryActive, [Customer Email], DeliveryDueAfter,
243 RangeCaveatText, ItemCaveatText, IsTaxInclusivePrice, SetParentID, SetPrice, IsSetHeader, Markdown,
244 CompanyName, UnfinancedPayments, TaxFreeSellingApplied
245 )
246 SELECT
247 @SO, sd.InternalOrderID, sd.StockDetailID, so.PadNumber,
248 so.SODate, so.DateRequired, @SalesPerson1, @SalesPerson2,
249 @MainAddress1, @MainAddress2, @MainAddress3, @MainAddress4,
250 @MainAddress5, @MainAddress6, @MainAddressPostcode, it.SKU,
251 pg.Class, CASE WHEN ISNULL(ra.Renamed, '') = '' THEN ra.Range ELSE ra.Renamed END, it.ModelNum, it.[Description],
252 '', '', sd.OptionCode, sd.Qty,
253 0, 0, 0, 0,
254 0, CASE WHEN ISNULL(sp.SupplierDebrand, '') = '' THEN sp.SupplierName ELSE sp.SupplierDebrand END AS [Supplier Name], @SalesOrderTotal, @CustomerTitle,
255 @CustomerInitials, @CustomerName, @CustomerAccount, @FlatNumber,
256 @HouseNumber, @HouseName, @ApprovedFinance, @UnapprovedFinance,
257 so.Complete, so.Cancelled, sd.Delivered, so.Printed,
258 sd.SOComments, @DeliveryHouseNumber, @DeliveryHouseName, @DeliveryFlatNumber,
259 @DeliveryAddress1, @DeliveryAddress2, @DeliveryAddress3, @DeliveryAddress4,
260 @DeliveryAddress5, @DeliveryAddress6, @DeliveryAddressPostcode, @DeliveryAddressInstruction,
261 @MainAddressInstruction, so.Quote,
262 sd.Imperfect,
263 so.OnHold, sd.OnDemand,
264 sd.OnOrder, sd.OnHand, so.DeliveryMethodID, @DeliveryBranch,
265 so.AmendNumber, so.AcceptPartDelivery, so.AcceptEarlyDelivery, so.QuoteExpiryDate,
266 0, @CustomerTelephone, @CustomerDaytime, @CustomerMobile,
267 ISNULL(so.HideSOLines, 0), sd.ActualLeadTime, @SellingBranchName, @SellingBranchAddress1,
268 @SellingBranchAddress2, @SellingBranchAddress3, @SellingBranchAddress4, @SellingBranchAddress5,
269 @SellingBranchAddress6, @SellingBranchPostcode, @SellingBranchTelephone, @SellingBranchFax,
270 pg.Description, so.PrintLinePrices, sd.ActualWidth, isnull(sd.IsRemnant, 0),
271 NULL, 0, 0, @CustomerEmail, so.DeliveryDueAfter,
272 @RangeCaveatText, @ItemCaveatText, @IsTaxInclusivePrice, @SPID, @SetPrice, 1, NULL,
273 ISNULL(comp.CompanyName, loc.LocationDesc), so.UnfinancedPayments, 0
274 FROM StockDetail sd
275 JOIN Items it ON sd.ItemID = it.ItemID
276 JOIN ProductGroup pg ON pg.ProductGroupPWCode = it.Grp
277 JOIN Ranges ra ON it.PWSupplierID = ra.PWSupplierID AND it.RangeID = ra.PWRangeID
278 JOIN Supplist sp ON it.PWSupplierID = sp.PWSupplierID
279 JOIN Supplier su ON sp.SupplierID = su.SupplierID
280 JOIN SalesOrder so ON so.SalesOrderID = @SO
281 JOIN Location loc ON so.OrderBranch = loc.LocationID
282 LEFT JOIN Company comp ON comp.CompanyID = loc.CompanyID
283 WHERE sd.StockDetailID = @SPID
284
285 FETCH c2 INTO @SPID, @SetPrice, @SalesPerson1, @SalesPerson2, @MainAddress1, @MainAddress2, @MainAddress3,
286 @MainAddress4, @MainAddress5, @MainAddress6, @MainAddressPostcode, @SalesOrderTotal,
287 @CustomerTitle, @CustomerInitials, @CustomerName, @CustomerAccount, @FlatNumber, @HouseNumber,
288 @HouseName, @ApprovedFinance, @UnapprovedFinance, @DeliveryHouseNumber, @DeliveryHouseName,
289 @DeliveryFlatNumber, @DeliveryAddress1, @DeliveryAddress2, @DeliveryAddress3, @DeliveryAddress4, @DeliveryAddress5,
290 @DeliveryAddress6, @DeliveryAddressPostcode, @DeliveryAddressInstruction, @MainAddressInstruction, @DeliveryBranch,
291 @CustomerTelephone, @CustomerDaytime, @CustomerMobile, @SellingBranchName, @SellingBranchAddress1, @SellingBranchAddress2,
292 @SellingBranchAddress3, @SellingBranchAddress4, @SellingBranchAddress5, @SellingBranchAddress6, @SellingBranchPostcode,
293 @SellingBranchTelephone, @SellingBranchFax, @RangeCaveatText, @ItemCaveatText, @IsTaxInclusivePrice, @CustomerEmail
294 END
295
296 CLOSE c2
297 DEALLOCATE c2
298 END
299
300 IF (SELECT COUNT(*) FROM StockDetail WHERE SalesOrderID = @SO AND Markdown IS NOT NULL) > 0
301 SET @AnyItemMarkedDown = 1
302 ELSE
303 SET @AnyItemMarkedDown = 0
304
305 SELECT 'Branch Copy ' AS Copy, [Sales Order Number], [Internal Order Number], [Stock Detail Number], [Order Pad Number], [Sales Order Date], [Date Required],
306 [Sales Person 1], [Sales Person 2], [Main Address 1], [Main Address 2], [Main Address 3], [Main Address 4], [Main Address 5], [Main Address 6], [Main Address Postcode],
307 [SKU Code], [Product Class], [Product Range], CASE WHEN @HideModelNo = 1 THEN '' ELSE [Model Number] END AS [Model Number], [Product Description 1], [Product Description 2], [Product Description 3], [Option Code], Quantity,
308 [MRP Price], [Original Selling Price], [Discounted Selling Price], [Final Selling Price], CONVERT(MONEY, ROUND(VAT, 2)) AS VAT, [Supplier Name], [Sales Order Total], [Customer Title], [Customer Initials],
309 [Customer Name], [Customer Account], [Flat Number], [House Number], [House Name], [Approved Finance], [Unapproved Finance], [Sales Order Complete],
310 [Sales Order Cancelled], [Sales Order Delivered], [Sales Order Printed], [Sales Order Comments], [Delivery House Number], [Delivery House Name], [Delivery Flat Number],
311 [Delivery Address 1], [Delivery Address 2], [Delivery Address 3], [Delivery Address 4], [Delivery Address 5], [Delivery Address 6], [Delivery Address Postcode],
312 [Delivery Address Instruction], [Main Address Instruction], Quotation, Imperfect, [On Hold], [On Demand], [On Order], [On Hand], [Delivery Method], [Delivery Branch], [Order Amendment Number],
313 [Accept Part Delivery], [Accept Early Delivery], [Quote Expiry], [Line Discount Price], [Customer Telephone], [Customer Daytime], [Customer Mobile], [Hide SO Lines],
314 [Dwell Time]=dbo.GetAppPar('DWELL_TIME', @CompanyID, 0),
315 [Lead Time],
316 Format=dbo.GetAppPar('SOA_Format', @CompanyID, 0),
317 [Quote Expiry Days]=dbo.GetAppPar('Quote_Expiry_Days', @CompanyID, 0),
318 Consolidate=dbo.GetBitAppParAsYN('Consolidate_SO', @CompanyID, 0),
319 [Exclude Supplier Name]=dbo.GetBitAppParAsYN('SOA_Exclude_Supplier', @CompanyID, 0),
320 [Single Logo]=dbo.GetBitAppParAsYN('Single_Logo', @CompanyID, 0),
321 [Show Retailer Address]=dbo.GetBitAppParAsYN('SOA_Show_Retailer_Address', @CompanyID, 0),
322 [MRP Description]=dbo.GetAppPar('MRP_Description', @CompanyID, 0),
323 [SOA Text 1]=dbo.GetAppPar('SOA_Text1', @CompanyID, 0),
324 [SOA Text 2]=dbo.GetAppPar('SOA_Text2', @CompanyID, 0),
325 [SOA Text 3]=dbo.GetAppPar('SOA_Text3', @CompanyID, 0),
326 [SOA Text 4]=dbo.GetAppPar('SOA_Text4', @CompanyID, 0),
327 [SOA Text 5]=dbo.GetAppPar('SOA_Text5', @CompanyID, 0),
328 [SOA Text 6]=dbo.GetAppPar('SOA_Text6', @CompanyID, 0),
329 [SOA Text 7]=dbo.GetAppPar('SOA_Text7', @CompanyID, 0),
330 [SOA Text 8]=dbo.GetAppPar('SOA_Text8', @CompanyID, 0),
331 [SOA Text 9]=dbo.GetAppPar('SOA_Text9', @CompanyID, 0),
332 [SOA Sig Text 1]=dbo.GetAppPar('SOA_Signature_Text', @CompanyID, 0),
333 [SOA Sig Text 2]=dbo.GetAppPar('SOA_Signature_Text2', @CompanyID, 0),
334 [SOA Sig Text 3]=dbo.GetAppPar('SOA_Signature_Text3', @CompanyID, 0),
335 [SOA Sig Text 4]=dbo.GetAppPar('SOA_Signature_Text4', @CompanyID, 0),
336 [SOA Sig Text 5]=dbo.GetAppPar('SOA_Signature_Text5', @CompanyID, 0),
337 [SOA TOTAL_MSG]=dbo.GetAppPar('SOA_TOTAL_MSG', @CompanyID, 0),
338 Receipt=dbo.GetSalesOrderAcknowledgementReceipt(@CompanyID, 0),
339 [Show SOA Text]=dbo.GetBitAppParAsYN('Show_SOA_Text', @CompanyID, 0),
340 [Selling Branch Name] ,
341 [Show VAT]=dbo.GetBitAppParAsYN('Show_SOA_VAT', @CompanyID, 0),
342 [Selling Branch Address 1], [Selling Branch Address 2], [Selling Branch Address 3], [Selling Branch Address 4], [Selling Branch Address 5], [Selling Branch Address 6],
343 [Selling Branch Postcode], [Selling Branch Telephone], [Selling Branch Fax], [Product Group],
344 Footer1=dbo.GetAppPar('Company_Number', @CompanyID, 0),
345 Footer2=dbo.GetAppPar('Company_Registered_Office1', @CompanyID, 0),
346 Footer3=dbo.GetAppPar('Company_Registered_Office2', @CompanyID, 0),
347 Footer4=dbo.GetAppPar('Company_VAT_Registration', @CompanyID, 0),
348 [Show Signature Text]=dbo.GetBitAppParAsYN('SOA_Show_Signature_Text', @CompanyID, 0),
349 [Signature Text]=dbo.GetAppPar('SOA_Signature_Text', @CompanyID, 0),
350 Layout=dbo.GetSalesOrderAcknowledgementLayout(@CompanyID, 0),
351 [Delivery Range Days]=dbo.GetAppPar('EXP_DELIVERY_RANGE_DAYS', @CompanyID, 0),
352 [Print Line Prices],
353 ActualWidth,
354 [Turnaround]=dbo.GetAppPar('MINIMUM_TURNAROUND_TIME', @CompanyID, 0),
355 Remnant, DeliveryDate, DeliveryConfirmed, DeliveryActive,
356 [Retailer Website]=dbo.GetAppPar('RETAILER_WEBSITE', @CompanyID, 0),
357 [SOA Shading]=dbo.GetBitAppParAsYN('SOA_Shading', @CompanyID, 0),
358 [Customer Email],
359 [Show Orig Price On Quotes]=dbo.GetBitAppParAsYN('SHOW_PRICE_ON_QUOTES', @CompanyID, 0),
360 [Print Delivery Due Days]=dbo.GetBitAppParAsYN('SOA_PRINT_DELIVERY_DUE_DAYS', @CompanyID, 0),
361 DeliveryDueAfter,
362 [Hide Logo]=dbo.GetBitAppParAsYN('SOA_HIDE_LOGO', @CompanyID, 0),
363 [UseDeliveryDays]=dbo.GetBitAppParAsYN('USE_DELIVERY_DAYS', @CompanyID, 0),
364 SOATitle=dbo.GetAppPar('SOA_TITLE', @CompanyID, 0),
365 RangeCaveatText, ItemCaveatText,
366 PrintCaveats=dbo.GetBitAppParAsYN('SOA_PRINT_CAVEATS', @CompanyID, 0),
367 [Keep Options Together]=dbo.GetBitAppParAsYN('SOA_KEEP_OPTIONS', @CompanyID, 0),
368 IsTaxInclusivePrice, ISNULL(SetParentID, 0) AS SetParentID, @Copy AS 'Copies', SetPrice, IsSetHeader, @ShowSetHeader AS ShowSetHeader, @ImagePath AS ImagePath, @SocialPath AS SocialPath,
369 MarkdownMessage=dbo.GetAppPar('SOA_MARKDOWN_MESSAGE', @CompanyID, 0),
370 @AnyItemMarkedDown AS AnyItemMarkedDown,
371 [HideDelDates]=dbo.GetBitAppParAsYN('SO_HIDE_DEL_DATES', @CompanyID, 0),
372 Markdown,
373 MarkdownLineMessage=dbo.GetAppPar('SOA_MARKDOWN_STK_TXT', @CompanyID, 0),
374 ShowLineDiscounts=dbo.GetBitAppParAsYN('SOA_SHOW_LINE_DISCOUNTS', @CompanyID, 0),
375 ShowImperfectNotes=dbo.GetBitAppParAsYN('SOA_SHOW_IMPERFECT_NOTES', @CompanyID, 0),
376 ShowMarkdownReasons = dbo.GetBitAppParAsYN('SOA_SHOW_MARKDOWN_REASONS', @CompanyID, 0),
377 @ShowSetDetails AS [Show Set Details],
378 VatRate, CompanyName, UnfinancedPayments,
379 [FinalVAT] = VAT,
380 [LineVAT] = LineDiscountedVATAmount,
381 [OrigVAT] = OriginalVATAmount,
382 TaxFreeSellingApplied, LineTotalPrice, MarkDownReason, StdVATCode, StdVATRate, StdVATDesc, LineVATCode, LineVATDesc
383 FROM #tmp
384 UNION ALL
385 SELECT 'Customer Copy ' AS Copy, [Sales Order Number], [Internal Order Number], [Stock Detail Number], [Order Pad Number], [Sales Order Date], [Date Required],
386 [Sales Person 1], [Sales Person 2], [Main Address 1], [Main Address 2], [Main Address 3], [Main Address 4], [Main Address 5], [Main Address 6], [Main Address Postcode],
387 [SKU Code], [Product Class], [Product Range], CASE WHEN @HideModelNo = 1 THEN '' ELSE [Model Number] END AS [Model Number], [Product Description 1], [Product Description 2], [Product Description 3], [Option Code], Quantity,
388 [MRP Price], [Original Selling Price], [Discounted Selling Price], [Final Selling Price], CONVERT(MONEY, ROUND(VAT, 2)) AS VAT, [Supplier Name], [Sales Order Total], [Customer Title], [Customer Initials],
389 [Customer Name], [Customer Account], [Flat Number], [House Number], [House Name], [Approved Finance], [Unapproved Finance], [Sales Order Complete],
390 [Sales Order Cancelled], [Sales Order Delivered], [Sales Order Printed], [Sales Order Comments], [Delivery House Number], [Delivery House Name], [Delivery Flat Number],
391 [Delivery Address 1], [Delivery Address 2], [Delivery Address 3], [Delivery Address 4], [Delivery Address 5], [Delivery Address 6], [Delivery Address Postcode],
392 [Delivery Address Instruction], [Main Address Instruction], Quotation, Imperfect,[On Hold], [On Demand], [On Order], [On Hand], [Delivery Method], [Delivery Branch], [Order Amendment Number],
393 [Accept Part Delivery], [Accept Early Delivery], [Quote Expiry], [Line Discount Price], [Customer Telephone], [Customer Daytime], [Customer Mobile], [Hide SO Lines],
394 [Dwell Time]=dbo.GetAppPar('DWELL_TIME', @CompanyID, 0),
395 [Lead Time],
396 Format=dbo.GetAppPar('SOA_Format', @CompanyID, 0),
397 [Quote Expiry Days]=dbo.GetAppPar('Quote_Expiry_Days', @CompanyID, 0),
398 Consolidate=dbo.GetBitAppParAsYN('Consolidate_SO', @CompanyID, 0),
399 [Exclude Supplier Name]=dbo.GetBitAppParAsYN('SOA_Exclude_Supplier', @CompanyID, 0),
400 [Single Logo]=dbo.GetBitAppParAsYN('Single_Logo', @CompanyID, 0),
401 [Show Retailer Address]=dbo.GetBitAppParAsYN('SOA_Show_Retailer_Address', @CompanyID, 0),
402 [MRP Description]=dbo.GetAppPar('MRP_Description', @CompanyID, 0),
403 [SOA Text 1]=dbo.GetAppPar('SOA_Text1', @CompanyID, 0),
404 [SOA Text 2]=dbo.GetAppPar('SOA_Text2', @CompanyID, 0),
405 [SOA Text 3]=dbo.GetAppPar('SOA_Text3', @CompanyID, 0),
406 [SOA Text 4]=dbo.GetAppPar('SOA_Text4', @CompanyID, 0),
407 [SOA Text 5]=dbo.GetAppPar('SOA_Text5', @CompanyID, 0),
408 [SOA Text 6]=dbo.GetAppPar('SOA_Text6', @CompanyID, 0),
409 [SOA Text 7]=dbo.GetAppPar('SOA_Text7', @CompanyID, 0),
410 [SOA Text 8]=dbo.GetAppPar('SOA_Text8', @CompanyID, 0),
411 [SOA Text 9]=dbo.GetAppPar('SOA_Text9', @CompanyID, 0),
412 [SOA Sig Text 1]=dbo.GetAppPar('SOA_Signature_Text', @CompanyID, 0),
413 [SOA Sig Text 2]=dbo.GetAppPar('SOA_Signature_Text2', @CompanyID, 0),
414 [SOA Sig Text 3]=dbo.GetAppPar('SOA_Signature_Text3', @CompanyID, 0),
415 [SOA Sig Text 4]=dbo.GetAppPar('SOA_Signature_Text4', @CompanyID, 0),
416 [SOA Sig Text 5]=dbo.GetAppPar('SOA_Signature_Text5', @CompanyID, 0),
417 [SOA TOTAL_MSG]=dbo.GetAppPar('SOA_TOTAL_MSG', @CompanyID, 0),
418 Receipt=dbo.GetSalesOrderAcknowledgementReceipt(@CompanyID, 0),
419 [Show SOA Text]=dbo.GetBitAppParAsYN('Show_SOA_Text', @CompanyID, 0),
420 [Selling Branch Name] ,
421 [Show VAT]=dbo.GetBitAppParAsYN('Show_SOA_VAT', @CompanyID, 0),
422 [Selling Branch Address 1], [Selling Branch Address 2], [Selling Branch Address 3], [Selling Branch Address 4], [Selling Branch Address 5], [Selling Branch Address 6],
423 [Selling Branch Postcode], [Selling Branch Telephone], [Selling Branch Fax], [Product Group],
424 Footer1=dbo.GetAppPar('Company_Number', @CompanyID, 0),
425 Footer2=dbo.GetAppPar('Company_Registered_Office1', @CompanyID, 0),
426 Footer3=dbo.GetAppPar('Company_Registered_Office2', @CompanyID, 0),
427 Footer4=dbo.GetAppPar('Company_VAT_Registration', @CompanyID, 0),
428 [Show Signature Text]=dbo.GetBitAppParAsYN('SOA_Show_Signature_Text', @CompanyID, 0),
429 [Signature Text]=dbo.GetAppPar('SOA_Signature_Text', @CompanyID, 0),
430 Layout=dbo.GetSalesOrderAcknowledgementLayout(@CompanyID, 0),
431 [Delivery Range Days]=dbo.GetAppPar('EXP_DELIVERY_RANGE_DAYS', @CompanyID, 0),
432 [Print Line Prices],
433 ActualWidth,
434 [Turnaround]=dbo.GetAppPar('MINIMUM_TURNAROUND_TIME', @CompanyID, 0),
435 Remnant, DeliveryDate, DeliveryConfirmed, DeliveryActive,
436 [Retailer Website]=dbo.GetAppPar('RETAILER_WEBSITE', @CompanyID, 0),
437 [SOA Shading]=dbo.GetBitAppParAsYN('SOA_Shading', @CompanyID, 0),
438 [Customer Email],
439 [Show Orig Price On Quotes]=dbo.GetBitAppParAsYN('SHOW_PRICE_ON_QUOTES', @CompanyID, 0),
440 [Print Delivery Due Days]=dbo.GetBitAppParAsYN('SOA_PRINT_DELIVERY_DUE_DAYS', @CompanyID, 0),
441 DeliveryDueAfter,
442 [Hide Logo]=dbo.GetBitAppParAsYN('SOA_HIDE_LOGO', @CompanyID, 0),
443 [UseDeliveryDays]=dbo.GetBitAppParAsYN('USE_DELIVERY_DAYS', @CompanyID, 0),
444 SOATitle=dbo.GetAppPar('SOA_TITLE', @CompanyID, 0),
445 RangeCaveatText, ItemCaveatText,
446 PrintCaveats=dbo.GetBitAppParAsYN('SOA_PRINT_CAVEATS', @CompanyID, 0),
447 [Keep Options Together]=dbo.GetBitAppParAsYN('SOA_KEEP_OPTIONS', @CompanyID, 0),
448 IsTaxInclusivePrice, ISNULL(SetParentID, 0) AS SetParentID, @Copy AS 'Copies', SetPrice, IsSetHeader, @ShowSetHeader AS ShowSetHeader, @ImagePath AS ImagePath,@SocialPath AS SocialPath,
449 MarkdownMessage=dbo.GetAppPar('SOA_MARKDOWN_MESSAGE', @CompanyID, 0),
450 @AnyItemMarkedDown AS AnyItemMarkedDown,
451 [HideDelDates]=dbo.GetBitAppParAsYN('SO_HIDE_DEL_DATES', @CompanyID, 0),
452 Markdown,
453 MarkdownLineMessage=dbo.GetAppPar('SOA_MARKDOWN_STK_TXT', @CompanyID, 0),
454 ShowLineDiscounts=dbo.GetBitAppParAsYN('SOA_SHOW_LINE_DISCOUNTS', @CompanyID, 0),
455 ShowImperfectNotes=dbo.GetBitAppParAsYN('SOA_SHOW_IMPERFECT_NOTES', @CompanyID, 0),
456 ShowMarkdownReasons=dbo.GetBitAppParAsYN('SOA_SHOW_MARKDOWN_REASONS', @CompanyID, 0),
457 @ShowSetDetails AS [Show Set Details],
458 VatRate, CompanyName, UnfinancedPayments,
459 [FinalVAT] = VAT,
460 [LineVAT] = LineDiscountedVATAmount,
461 [OrigVAT] = OriginalVATAmount,
462 TaxFreeSellingApplied, LineTotalPrice, MarkDownReason, StdVATCode, StdVATRate, StdVATDesc, LineVATCode, LineVATDesc
463 FROM #tmp
464 UNION ALL
465 SELECT 'Copy ' AS Copy, [Sales Order Number], [Internal Order Number], [Stock Detail Number], [Order Pad Number], [Sales Order Date], [Date Required],
466 [Sales Person 1], [Sales Person 2], [Main Address 1], [Main Address 2], [Main Address 3], [Main Address 4], [Main Address 5], [Main Address 6], [Main Address Postcode],
467 [SKU Code], [Product Class], [Product Range], CASE WHEN @HideModelNo = 1 THEN '' ELSE [Model Number] END AS [Model Number], [Product Description 1], [Product Description 2], [Product Description 3], [Option Code], Quantity,
468 [MRP Price], [Original Selling Price], [Discounted Selling Price], [Final Selling Price], CONVERT(MONEY, ROUND(VAT, 2)) AS VAT, [Supplier Name], [Sales Order Total], [Customer Title], [Customer Initials],
469 [Customer Name], [Customer Account], [Flat Number], [House Number], [House Name], [Approved Finance], [Unapproved Finance], [Sales Order Complete],
470 [Sales Order Cancelled], [Sales Order Delivered], [Sales Order Printed], [Sales Order Comments], [Delivery House Number], [Delivery House Name], [Delivery Flat Number],
471 [Delivery Address 1], [Delivery Address 2], [Delivery Address 3], [Delivery Address 4], [Delivery Address 5], [Delivery Address 6], [Delivery Address Postcode],
472 [Delivery Address Instruction], [Main Address Instruction], Quotation, Imperfect, [On Hold], [On Demand], [On Order], [On Hand], [Delivery Method], [Delivery Branch], [Order Amendment Number],
473 [Accept Part Delivery], [Accept Early Delivery], [Quote Expiry], [Line Discount Price], [Customer Telephone], [Customer Daytime], [Customer Mobile], [Hide SO Lines],
474 [Dwell Time]=dbo.GetAppPar('DWELL_TIME', @CompanyID, 0),
475 [Lead Time],
476 Format=dbo.GetAppPar('SOA_Format', @CompanyID, 0),
477 [Quote Expiry Days]=dbo.GetAppPar('Quote_Expiry_Days', @CompanyID, 0),
478 Consolidate=dbo.GetBitAppParAsYN('Consolidate_SO', @CompanyID, 0),
479 [Exclude Supplier Name]=dbo.GetBitAppParAsYN('SOA_Exclude_Supplier', @CompanyID, 0),
480 [Single Logo]=dbo.GetBitAppParAsYN('Single_Logo', @CompanyID, 0),
481 [Show Retailer Address]=dbo.GetBitAppParAsYN('SOA_Show_Retailer_Address', @CompanyID, 0),
482 [MRP Description]=dbo.GetAppPar('MRP_Description', @CompanyID, 0),
483 [SOA Text 1]=dbo.GetAppPar('SOA_Text1', @CompanyID, 0),
484 [SOA Text 2]=dbo.GetAppPar('SOA_Text2', @CompanyID, 0),
485 [SOA Text 3]=dbo.GetAppPar('SOA_Text3', @CompanyID, 0),
486 [SOA Text 4]=dbo.GetAppPar('SOA_Text4', @CompanyID, 0),
487 [SOA Text 5]=dbo.GetAppPar('SOA_Text5', @CompanyID, 0),
488 [SOA Text 6]=dbo.GetAppPar('SOA_Text6', @CompanyID, 0),
489 [SOA Text 7]=dbo.GetAppPar('SOA_Text7', @CompanyID, 0),
490 [SOA Text 8]=dbo.GetAppPar('SOA_Text8', @CompanyID, 0),
491 [SOA Text 9]=dbo.GetAppPar('SOA_Text9', @CompanyID, 0),
492 [SOA Sig Text 1]=dbo.GetAppPar('SOA_Signature_Text', @CompanyID, 0),
493 [SOA Sig Text 2]=dbo.GetAppPar('SOA_Signature_Text2', @CompanyID, 0),
494 [SOA Sig Text 3]=dbo.GetAppPar('SOA_Signature_Text3', @CompanyID, 0),
495 [SOA Sig Text 4]=dbo.GetAppPar('SOA_Signature_Text4', @CompanyID, 0),
496 [SOA Sig Text 5]=dbo.GetAppPar('SOA_Signature_Text5', @CompanyID, 0),
497 [SOA TOTAL_MSG]=dbo.GetAppPar('SOA_TOTAL_MSG', @CompanyID, 0),
498 Receipt=dbo.GetSalesOrderAcknowledgementReceipt(@CompanyID, 0),
499 [Show SOA Text]=dbo.GetBitAppParAsYN('Show_SOA_Text', @CompanyID, 0),
500 [Selling Branch Name] ,
501 [Show VAT]=dbo.GetBitAppParAsYN('Show_SOA_VAT', @CompanyID, 0),
502 [Selling Branch Address 1], [Selling Branch Address 2], [Selling Branch Address 3], [Selling Branch Address 4], [Selling Branch Address 5], [Selling Branch Address 6],
503 [Selling Branch Postcode], [Selling Branch Telephone], [Selling Branch Fax], [Product Group],
504 Footer1=dbo.GetAppPar('Company_Number', @CompanyID, 0),
505 Footer2=dbo.GetAppPar('Company_Registered_Office1', @CompanyID, 0),
506 Footer3=dbo.GetAppPar('Company_Registered_Office2', @CompanyID, 0),
507 Footer4=dbo.GetAppPar('Company_VAT_Registration', @CompanyID, 0),
508 [Show Signature Text]=dbo.GetBitAppParAsYN('SOA_Show_Signature_Text', @CompanyID, 0),
509 [Signature Text]=dbo.GetAppPar('SOA_Signature_Text', @CompanyID, 0),
510 Layout=dbo.GetSalesOrderAcknowledgementLayout(@CompanyID, 0),
511 [Delivery Range Days]=dbo.GetAppPar('EXP_DELIVERY_RANGE_DAYS', @CompanyID, 0),
512 [Print Line Prices],
513 ActualWidth,
514 [Turnaround]=dbo.GetAppPar('MINIMUM_TURNAROUND_TIME', @CompanyID, 0),
515 Remnant, DeliveryDate, DeliveryConfirmed, DeliveryActive,
516 [Retailer Website]=dbo.GetAppPar('RETAILER_WEBSITE', @CompanyID, 0),
517 [SOA Shading]=dbo.GetBitAppParAsYN('SOA_Shading', @CompanyID, 0),
518 [Customer Email],
519 [Show Orig Price On Quotes]=dbo.GetBitAppParAsYN('SHOW_PRICE_ON_QUOTES', @CompanyID, 0),
520 [Print Delivery Due Days]=dbo.GetBitAppParAsYN('SOA_PRINT_DELIVERY_DUE_DAYS', @CompanyID, 0),
521 DeliveryDueAfter,
522 [Hide Logo]=dbo.GetBitAppParAsYN('SOA_HIDE_LOGO', @CompanyID, 0),
523 [UseDeliveryDays]=dbo.GetBitAppParAsYN('USE_DELIVERY_DAYS', @CompanyID, 0),
524 SOATitle=dbo.GetAppPar('SOA_TITLE', @CompanyID, 0),
525 RangeCaveatText, ItemCaveatText,
526 PrintCaveats=dbo.GetBitAppParAsYN('SOA_PRINT_CAVEATS', @CompanyID, 0),
527 [Keep Options Together]=dbo.GetBitAppParAsYN('SOA_KEEP_OPTIONS', @CompanyID, 0),
528 IsTaxInclusivePrice, ISNULL(SetParentID, 0) AS SetParentID, @Copy AS 'Copies', SetPrice, IsSetHeader, @ShowSetHeader AS ShowSetHeader, @ImagePath AS ImagePath, @SocialPath AS SocialPath,
529 MarkdownMessage=dbo.GetAppPar('SOA_MARKDOWN_MESSAGE', @CompanyID, 0),
530 @AnyItemMarkedDown AS AnyItemMarkedDown,
531 [HideDelDates]=dbo.GetBitAppParAsYN('SO_HIDE_DEL_DATES', @CompanyID, 0),
532 Markdown,
533 MarkdownLineMessage=dbo.GetAppPar('SOA_MARKDOWN_STK_TXT', @CompanyID, 0),
534 ShowLineDiscounts=dbo.GetBitAppParAsYN('SOA_SHOW_LINE_DISCOUNTS', @CompanyID, 0),
535 ShowImperfectNotes=dbo.GetBitAppParAsYN('SOA_SHOW_IMPERFECT_NOTES', @CompanyID, 0),
536 ShowMarkdownReasons=dbo.GetBitAppParAsYN('SOA_SHOW_MARKDOWN_REASONS', @CompanyID, 0),
537 @ShowSetDetails AS [Show Set Details],
538 VatRate, CompanyName, UnfinancedPayments,
539 [FinalVAT] = VAT,
540 [LineVAT] = LineDiscountedVATAmount,
541 [OrigVAT] = OriginalVATAmount,
542 TaxFreeSellingApplied, LineTotalPrice, MarkDownReason,StdVATCode, StdVATRate, StdVATDesc, LineVATCode, LineVATDesc
543 FROM #tmp
544
545
546
547
548
549
550
551
552
553
554GO
555SET QUOTED_IDENTIFIER OFF
556GO
557SET ANSI_NULLS ON
558GO