Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 stored procedures

Author  Topic 

saahil_k
Starting Member

18 Posts

Posted - 2008-02-01 : 23:36:01
hi
i am new to SQL server.how can i write a stored procedure to find out the currently logged in user and print if the user is using windows authentication or sql authentication for his login
thanks

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-01 : 23:49:11
select distinct loginame, 'windows authentication' from master.sys.sysprocesses where nt_username is not null
union all
select distinct loginame, 'sql authentication' from master.sys.sysprocesses where nt_username is null
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-01 : 23:51:58
hi,
use SYSTEM_USER
SELECT SYSTEM_USER,
CASE WHEN CHARINDEX('\',SYSTEM_USER) > 0
THEN 'windows authentication'
ELSE 'sql authentication'
END AS Authentication
Go to Top of Page

saahil_k
Starting Member

18 Posts

Posted - 2008-02-01 : 23:59:11
hi,
thanks a lot i got it.
Go to Top of Page

Paulrpr
Starting Member

2 Posts

Posted - 2008-02-02 : 00:39:00
Is their any way to use ARRAY in Stored procedures

PAUL
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-02 : 00:41:25
T-sql doesn't support array.
Go to Top of Page

saahil_k
Starting Member

18 Posts

Posted - 2008-02-02 : 00:53:43
hi,
can anybody refer good website for performance tuning and also if possible video tutorials.
thanks
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-02 : 01:08:47
TechNet has many articles of that.
Go to Top of Page

saahil_k
Starting Member

18 Posts

Posted - 2008-02-02 : 19:04:40
Hello all,
what is the query to get the date part only,time part only for get date().I want the date and time should be seperate.
thanks
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-02 : 21:30:04
Use datepart function.
Go to Top of Page

saahil_k
Starting Member

18 Posts

Posted - 2008-02-02 : 21:57:59
i got it by using the convert function
thanks
Go to Top of Page

saahil_k
Starting Member

18 Posts

Posted - 2008-02-02 : 23:15:53
Hello,
Query to find the Newest and Oldest table created in Adventure Works.
Thanks in advance
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-02 : 23:48:57
Query sys.objects in the db.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-02 : 23:53:14
Oldest created table(s):-
SELECT s.* from sysobjects s
INNER JOIN (SELECT MIN(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'

Newest created table(s):-
SELECT s.name from sysobjects s
INNER JOIN (SELECT MAX(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-02-03 : 23:55:42
quote:
Originally posted by visakh16

Oldest created table(s):-
SELECT s.* from sysobjects s
INNER JOIN (SELECT MIN(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'

Newest created table(s):-
SELECT s.name from sysobjects s
INNER JOIN (SELECT MAX(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'


use 'on' but not 'where' in <where t.crdate=s.crdate> part.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-04 : 01:28:06
quote:
Originally posted by saahil_k

i got it by using the convert function
thanks


If it is only formation, then do it in front end application
Also post unrelated questions as a new topic

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-08 : 01:16:49
quote:
Originally posted by visakh16

Oldest created table(s):-
SELECT s.* from sysobjects s
INNER JOIN (SELECT MIN(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'

Newest created table(s):-
SELECT s.name from sysobjects s
INNER JOIN (SELECT MAX(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'





select top 1 * from sysobjects WHERE type='U' order by crdate asc

select top 1 * from sysobjects WHERE type='U' order by crdate desc

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-08 : 03:13:50
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

Oldest created table(s):-
SELECT s.* from sysobjects s
INNER JOIN (SELECT MIN(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'

Newest created table(s):-
SELECT s.name from sysobjects s
INNER JOIN (SELECT MAX(crdate) AS crdate
FROM sysobjects
WHERE type='U')t
where t.crdate=s.crdate
and s.type='U'





select top 1 * from sysobjects WHERE type='U' order by crdate asc

select top 1 * from sysobjects WHERE type='U' order by crdate desc

Madhivanan

Failing to plan is Planning to fail


yup. this was easier way. sorry didnt felt this then
Go to Top of Page
   

- Advertisement -