TMSScript & Temp files

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mohdrashid
Posts: 6
Joined: Wed 18 Jan 2006 04:02
Location: Singapore

TMSScript & Temp files

Post by mohdrashid » Fri 06 Jul 2012 03:21

hi there,
i got the following statements.
the line
SQL.Add('If object_id('''+'tempdb..#POSSales'+''') IS NOT NULL DROP TABLE #POSSales')

does not seems to work during execution. it does not detect the #POSSales table in the object_id. This result a error; #possales already exist in the subsequent loop.

Please advise. i am using I am using windows 7, delphi xe.

regards and thanks in advance.
rashid.

Code: Select all

      repeat
        WITH MSScriptPOSIm DO
          BEGIN
            SQL.Add('If object_id('''+'tempdb..#POSSales'+''') IS NOT NULL DROP TABLE #POSSales');
            SQL.Add('CREATE TABLE #POSSales (InvoiceNumber varChar(11), SalesDate varchar(11), CustomerNumber varchar(20), ItemNumber varchar(30), Qty real, [Description] varcHar(255),');
            SQL.Add('ExTaxPrice Money Default 0 Not Null, IncTaxPrice Money Default 0 Not Null, TaxCode Varchar(3), Inclusive Varchar(1), Location Varchar(10), ExportDate VarcHar(11),');
            SQL.Add('TotalInvAmt Money Default 0 Not Null)');
            SQL.Add('BULK INSERT #POSSales FROM '''+ DumpFileLocation+SearchResult.Name + '''WITH (FIRSTROW = 1)');
            SQL.ADD('INSERT INTO [POSSales] ([InvoiceNumber],[SalesDate],[CustomerNumber],[ItemNumber],[Qty],[Description],[ExTaxPrice],');
			      SQL.ADD('[IncTaxPrice],[TaxCode],[Inclusive],[Location],[ExportDate],[TotalInvAmt],[ImpFileName],[EnteredDate])');
			      SQL.ADD('SELECT [InvoiceNumber],[SalesDate],[CustomerNumber],[ItemNumber],[Qty],[Description],[ExTaxPrice],');
			      SQL.ADD('[IncTaxPrice],[TaxCode],[Inclusive],[Location],[ExportDate],[TotalInvAmt],'''+SearchResult.Name+''',GETDATE() FROM [#POSSales]');
            Execute;
          END;
        until FindNext(searchresult) <> 0;
        FindClose(searchResult);
      end;

AndreyZ

Re: TMSScript & Temp files

Post by AndreyZ » Fri 06 Jul 2012 07:18

Hello,

The point is that you are trying to drop the POSSales table and to re-create it in the same statement. To avoid this problem, you should add the ';' symbol to the end of the SQL statement where you drop the POSSales table. Here is a code example:

Code: Select all

SQL.Add('If object_id(''tempdb..#POSSales'') IS NOT NULL DROP TABLE #POSSales;');

mohdrashid
Posts: 6
Joined: Wed 18 Jan 2006 04:02
Location: Singapore

Re: TMSScript & Temp files

Post by mohdrashid » Wed 11 Jul 2012 13:55

hi,
thanks for the advice but not working. I am getting same error.
Some how the temp table is being detected in the list.

any one?

regards
rashid

AndreyZ

Re: TMSScript & Temp files

Post by AndreyZ » Thu 12 Jul 2012 10:44

I cannot reproduce the problem. Please specify the following:
- the exact version of SDAC. You can learn it from the About sheet of TMSConnection Editor;
- the exact version of SQL Server and client. You can learn it from the Info sheet of TMSConnection Editor.

mohdrashid
Posts: 6
Joined: Wed 18 Jan 2006 04:02
Location: Singapore

Re: TMSScript & Temp files

Post by mohdrashid » Fri 13 Jul 2012 02:20

hi
SDAC ver 5.10.0.8 for delphi xe

Microsoft SQL Server: 10.50.2500
Microsoft SQL Server Native Client 10.0: 10.50.2500.0

thks in adv

regards
rashid

AndreyZ

Re: TMSScript & Temp files

Post by AndreyZ » Fri 13 Jul 2012 10:01

Please make sure that the MSScriptPOSIm.Delimiter property is set to ';' .

mohdrashid
Posts: 6
Joined: Wed 18 Jan 2006 04:02
Location: Singapore

Re: TMSScript & Temp files

Post by mohdrashid » Fri 20 Jul 2012 09:02

hi there,
it is working. thank you.

regards
rashid.

AndreyZ

Re: TMSScript & Temp files

Post by AndreyZ » Fri 20 Jul 2012 09:47

It is good to see that this problem was solved. If any other questions come up, please contact us.

Post Reply