parameterizing SQL scripts

  • I need to use a system value, for example, output from DOS hostname command, in a script.

    For example:

    exec sp_grantlogin 'hostname\username'

    I'm familiar with this kind of feature in Oracle, but haven't been successful finding it in SQL.

    Your help is appreciated.

    Thanks.

  • Depending on what you want, there are a couple of ways to go about getting it.

    First, SQL Server has a number of functions that will return system data already built in. Look up "system functions" in Books Online for a full list of them and what they do.

    Second, you can use a CLR proc/function to get just about anything system-wise into SQL.

    Third, you can use xp_cmdshell to get some of this data and dump it into tables. I generally recommend against this, because of the security issues with it, but it can be applicable in certain circumstances.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply