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
 problem in group by

Author  Topic 

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2007-03-01 : 00:12:41
hi, this is my spc:

CREATE PROCEDURE HRLogin_splogincheck(@username varchar(50),@password varchar(50))
As
begin
select count(*) as count,user_name from usermaster group by user_name where userid=@username and password=@password
end
GO
i am getting error,i thind i made some mistake in query,can any one please help me to rectify the error please

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-01 : 00:16:14
[code]
CREATE PROCEDURE HRLogin_splogincheck(@username varchar(50),@password varchar(50))
As
begin
select count(*) as count, user_name
from usermaster
where userid = @username
and password = @password

group by user_name
end
GO
[/code]


KH

Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2007-03-01 : 00:26:32
thank you khtan i got it.
Go to Top of Page

jsinks
Starting Member

13 Posts

Posted - 2007-03-01 : 01:46:44
Hi, sqllover;

sorry but can you give me an example of what you wud use that sp for?
am very very new to this. Ll appreciate.
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2007-03-01 : 03:32:04
hi jsinks canu explain clearly so that i can help you
Go to Top of Page

jsinks
Starting Member

13 Posts

Posted - 2007-03-01 : 04:54:47
I meant to say what does this procedure do? How can you use it? gve an example maybe
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2007-03-01 : 04:59:29
hi, i am doing this for login validation and getting user_name for other purpose.if count=0 means invalid username, count=1 means valid username.
Go to Top of Page

jsinks
Starting Member

13 Posts

Posted - 2007-03-01 : 06:18:48
ok, thanks.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-01 : 08:03:22
quote:
Originally posted by sqllover

hi, i am doing this for login validation and getting user_name for other purpose.if count=0 means invalid username, count=1 means valid username.



If sole purpose of this SP is to check the existence of user name, IF EXISTS will perform better than GROUP BY.

IF EXISTS(Select * 
from usermaster
where userid = @username
and password = @password)
-- User Name found
Select 1
Else
-- User name not found
Select 0


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -