I'm trying to run the following query on MS SQL 2012 Express:
Select (
Select Id, Salt, Password, BannedEndDate
from Users
where username = '" + LoginModel.Username + "'
), (
Select Count(*)
From LoginFails
where username = '" + LoginModel.Username + "'
And IP = '" + Request.ServerVariables["REMOTE_ADDR"] + "')"
);
But I get the following error:
Only one expression can be specified in the
select
list when the subquery is not introduced withEXISTS
.
How can I solve this problem?
Try this one -
"SELECT
ID, Salt, password, BannedEndDate
, (
SELECT COUNT(1)
FROM dbo.LoginFails l
WHERE l.UserName = u.UserName
AND IP = '" + Request.ServerVariables["REMOTE_ADDR"] + "'
) AS cnt
FROM dbo.Users u
WHERE u.UserName = '" + LoginModel.Username + "'"