Tuesday, February 9, 2010

Comparing the Contents of Two Tables

Comparing the Contents of Two Tables: create table a(c1 int,c2 varchar(3),c3 varchar(3)) create table b(c1 int,c2 varchar(3),c3 varchar(3))insert into a values(1,'x','y')insert into a values(2,'xx','y')insert into a values(3,'x','y')insert into b values(1,'x','y')insert into b values(2,'x','y')insert into b values(3,'x','yy')select * from a C1 C2 C3----- -- -- 1 x y 2 xx y 3 x yselect * from b C1 C2 C3----- -- -- 1 x y 2 x y 3...

Wednesday, February 3, 2010

Spool operation in SQL server

SQL Server doesn't have a SPOOL command like Oracle does for writing to files,But there are other ways of doing what we want.1. For reading, use xp_cmdshell and the ECHO command. Use the > or >> redirection symbols to either create or append to a file.xp_cmdshell "@ECHO test message >> C:\file.fil"2. Put the information you want into a table (note this can't be an ordinary temporary table, but it can be a global temporary table) and then bcp it out to a file via xp_cmdshell.xp_cmdshell "bcp .. out c:\file.fil -Usa -P -c"3. Run the...