Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    51

    Unanswered: script calling script

    can a SQL Script refer to and call another sql script?

    is there a synatax to run another sql script from within a sql script?

    how do you refer to and locate the script you want to run from within another?

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    you could do it by invoking sqlcmd or osql via xp_cmdshell. but why???

  3. #3
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    e.g.
    Code:
    C:\tmp>type s1.sql
    select 'strt_time'=getdate() into #t1
    select count(*) as rows from master..syscolumns where name like '%[a-zA-Z]%'
    :r s2.sql
    select count(*) as rows from master..sysobjects where name like '%[a-zA-Z]%'
    :r s2.sql
    drop table #t1
    go
    
    C:\tmp>type s2.sql
    select 'elapsed(ms)'=datediff(ms,strt_time,getdate()) from #t1
    go
    
    C:\tmp>osql -n -Usa -Spdsrv -i s1.sql
    Password:
    (1 row affected)
     rows
     -----------
            5080
    
    (1 row affected)
     elapsed(ms)
     -----------
              46
    
    (1 row affected)
     rows
     -----------
            1400
    
    (1 row affected)
     elapsed(ms)
     -----------
              76
    
    (1 row affected)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •