INSERT shows strange behaviour (or I'm not getting it)

INSERT shows strange behaviour (or I'm not getting it)

Post by Wilber » Sat, 24 Jan 2004 12:26:05



I have created a table that consists of 1 collumn of type varchar and length 250. In a SQL-script, I first insert some header data into the table and then I use xp_cmdshell to pass a command to the OS and to have the results stored in the table. The syntax for the latter is: "INSERT <table> EXEC master..xp_cmdshell 'dir *.doc /s".
When I omit the "/s" for a search in only the root of my drive, all is fine. I see my header first and then the results of the search. When I activate the "/s" again, the results are strange. First, there are some result lines in the table followed by my header and some more result data (I open the table from the Enterprise Manager).
Why are the results all garbled up? I cuurenlty pass a search for ".doc", ".xls" and ".ppt" files to the OS and I want to do some searches and modifications on the results later> For these it would help me if the results were stored as I'd like them to be. Please advise.
 
 
 

INSERT shows strange behaviour (or I'm not getting it)

Post by David Porta » Sat, 24 Jan 2004 12:52:13


Did you specify ORDER BY when you queried your table? A table is an
unordered set so you can't expect to get the data back in any particular
sequence unless you use ORDER BY.

The DIR output won't easily insert directly into a table in a meaningful
way. You may be better off piping the output to a file, then using DTS to
import the result.

--
David Portas
------------
Please reply only to the newsgroup
--

 
 
 

INSERT shows strange behaviour (or I'm not getting it)

Post by Tibor Karasz » Wed, 28 Jan 2004 10:16:22


You can shell out to BCP and specify for BCP the appropriate column separators.

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sql...


Quote:> Is there a way to create a csv-file directly from the shell call using master..xp_cmdshell?

 
 
 

INSERT shows strange behaviour (or I'm not getting it)

Post by Roji. P. Thoma » Wed, 28 Jan 2004 11:48:38


bcp is a command line bulk copy utility available with SQL Server.
see BOL for more abt bcp. But dont ask me whats BOL

--
Roji. P. Thomas
SQL Server Programmer
--------------------------------------

Quote:> With the danger of sounding like a total n00b: What do you mean by "shell

out to BCP"?
 
 
 

INSERT shows strange behaviour (or I'm not getting it)

Post by Tibor Karasz » Wed, 28 Jan 2004 14:30:31


Use xp_cmdshell to execute BCP. Like:

EXEC xp_cmdshell 'BCP ... /o... /i... etc'

BOL is SQL Server Books Online.

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sql...


Quote:> With the danger of sounding like a total n00b: What do you mean by "shell out to BCP"?

 
 
 

1. Strange behaviour of 'NOT IN'

Hi,

I'm having a curious frustrating problem with 'NOT IN'.
I have a table defining 'unities' (TUnidades) which has 13 different lines.
Its identifier is 'Id'.
I have another table defining people (TPessoas), with foreign key to
TUnidades, which is 'unid_Id'. This field has 12 distinct values in the
whole table.

Now, I want to get all those values of TUnidades.Id which do not exist in
TPessoas.Unid_Id. So, I write the following query

select Id from tunidade
where Id not in
(select distinct unid_Id from TPEssoas).

I should get 1 record, but I get 0!

If I rewrite slightly the query, like this,

select Id from tunidade
where Id not in
(select distinct unid_Id from TPEssoas
where unid_Id <> 0)

or any other condition over unid_Id that doesn't affect the result (there is
no record where unid_Id is 0), I get the right result, with 1 record.

Is this a flaw of the SQL, or of the engine ? How can I know if I have more
of these errors undetected ?

Thank you

Alexandre Pinto

Novabase Porto
Sistema de Informa??o Interno

2. Where can I order Paradox 8 standalone version?

3. Strange Grid Combobox Behaviour (same value shown in every row)

4. SQLServer Database Devices list

5. Strange behaviour of bcp and BULK INSERT

6. Use filter criteria in JOIN clause or WHERE clause?

7. Strange Insert Behaviour

8. APPLICATION DEVELOPER/ Intranet Applications, Extranet applications- WA

9. Not sure where to put this--strange ODBC behavior (or I think it's strange)

10. ADO Recordset's strange behaviour when filtered using adFilterConflictingRecords

11. Strange behaviour: Not accepting connections

12. Strange Behaviour VB6 ADO MSACCESS Added Records do not appear immediately