T-SQL

  • 1)I am using print command to display a user and also getdate function but i see result in the same result set, how can i get them in 2 diff columns

     

    2) when i print user iam getting as dbo coz am asigned as admin, how can i get my original id instead of dbo.

  • If you want columns you need to return a record set not a message and should therefore use select and not print.

    By original ID do you mean Login instead of user? If so try System_User.

    so/

    select getdate(), System_User

    www.sql-library.com[/url]

  • When I use system_user I get sa id but i need to get windows id.

    so do u mean I cant display the result in 2 columns by using print, only select can do that?

     

     

  • When logging on as SA, there is no matchning LanManName.


    N 56°04'39.16"
    E 12°55'05.25"

  • well you could delimit the values

    declare @result varchar(100)

    select @result = cast(getdate() as varchar(20))+','+system_user

    print @result

    this wouldnt really be columns.

    Why you want to use print?

    www.sql-library.com[/url]

  • Yep but system_user will return windows authentication logins. If thats what you need??

    www.sql-library.com[/url]

  • still am getting the result with coma seperated, am not getting in diff columns

    but when i use sustem_user am getting as SA, how can i get my user name.

  • can describe what you mean by user name please.

    www.sql-library.com[/url]

  • my windows user id..under my name.

  • there is likely to be way of getting the windows account you are loged onto the network under using T-SQL when you are logged into SQL as SA. Proiler seems to know for example.

    But why are you logged in as sa. Why not create a new sql login for your windows account and login under that. the sa account shouldnt really be used except in special circumstances and if you use windows authentication you will be able to the return the current user with system_user...

    www.sql-library.com[/url]

  • PRINT produces a kind of message - a string - rather than a recordset, so it doesn't have columns in the sense of fields. You could mess around with padding your strings and adding crlf characters to the end of a 'line', but you would probably be better off returning a recordset using SELECT, since this is much more flexible, can be passed to applications, is automatically displayed in columns whatever method you choose of displaying it, including in a non-fixed width font, and is THE entity with which just about all SQL is concerned. It incorporates metadata such as datatypes. You definitely need to understand the difference between this and a PRINTed string. Apologies if you already do.

    I'm not so sure that you can retrieve the NT user when SQL security is used. No doubt someone knows a way....?

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

Viewing 11 posts - 1 through 10 (of 10 total)

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