Can Windows variables Be Used Within T-SQL

  • Hi Folks

    just want to know if there is a way to incorporate Windows Variable(s) in some T-SQL using DBMAIL

    Here is what I have:

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'DBCC Check Success',

    @recipients = 'james.cox.ctr@losangeles.af.mil',

    @body = 'Test DBMail from SQLCMDS prompt.',

    @subject = ' Test - DBCC Check Success' ;

    GO

    I would like to add the COMPUTERNAME variable ==> %COMPUTERNAME% in @subject

    Is that possible ?

    Thanks

    Jim

  • Either Host_Name() or @@SERVERNAME should give you what you need. Host_Name will give you the name of the workstation that initiated the process, @@SERVERNAME will give you the name of the server that actually runs it.

    Drew

    NOTE: The "workstation" may also be a server. This happens when the process is initiated by a SQL job, for example.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • HI Drew

    that will work

    but how do i concantenate it to the string in @subject=

    if my @@SERVERNAME is NSAB-SS73-ORA-N

    then

    I want it to look like this:

    NSAB-SS73-ORA-N Test - DBCC Check Success

    Jim

  • JC-3113 (9/15/2010)


    HI Drew

    that will work

    but how do i concantenate it to the string in @subject=

    if my @@SERVERNAME is NSAB-SS73-ORA-N

    then

    I want it to look like this:

    NSAB-SS73-ORA-N Test - DBCC Check Success

    Jim

    You'll need to do the concatenation in a variable defined before the EXEC and then use the variable in the EXEC.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

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