Wednesday, January 31, 2007

SQL SERVER:HOW TO RUN A SQL SCRIPT WHICH IS IN YOUR LOCAL DRIVE?

a/
Create a file in C:\ drive Hasim.sql is as follows:-

SELECT t1.empname [Employee], COALESCE(t2.empname, 'No manager') [Manager] FROM emp t1 LEFT OUTER JOIN emp t2 ON t1.mgrid = t2.empid;

b/
Create a table emp in tempdb


use tempdb;

CREATE TABLE emp
(
empid int,
mgrid int,
empname char(10)
);

c/
Populate the table


INSERT emp SELECT 1,2,'Hasim'
INSERT emp SELECT 2,3,'Arun'
INSERT emp SELECT 3,NULL,'Divya'
INSERT emp SELECT 4,2,'Parthiban'
INSERT emp SELECT 5,2,'Priyanka'

d/
Run that sql file in C:\ drive as follows:-


EXEC master..xp_cmdshell 'isql -SAHASIM -Usa -Psa -ic:\Hasim.sql -n'

---: I am not responsible for any damages happened from the suggestion of my blog :---
Reach me at : m.a.hasim@inbox.com

Labels:

0 Comments:

Post a Comment

<< Home