Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if statement to resolve sql depending on user id 1

Status
Not open for further replies.

aarellano

MIS
Oct 22, 2007
168
US
Hello,

I have an asp page that checks the user id, then goes to an acces db to check user credentials, if the user gets authenticated, the user gets redirected to see his data only. This works well. I am trying to ad an admin user. To be able to see all the records

here is what my code looks like
Code:
<%

Username = Request.Form("txtUsername")	
	Password = Request.Form("txtPassword")
	
	'Build connection with database
	set conn = server.CreateObject ("ADODB.Connection")		
	conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("\mydb.mdb")
	set rs = server.CreateObject ("ADODB.Recordset")

	
	rs.Open "SELECT * FROM spartan where username='" & Session("Username")& "'", conn, 1 
	
	Dim presentuserid

presentuserid=rs("userid")


strTableName="WEBSPA.WEEKLYSLS"
Session("OwnerID") = Session("_" & strTableName & "_OwnerID") ' to support older events and default values

strOriginalTableName="WEB.WEEKLY"

gPageSize=50

gstrOrderBy=""
if len(gstrOrderBy)>0 and lcase(mid(gstrOrderBy,1,8))<>"order by" then gstrOrderBy="order by " & gstrOrderBy
	


gsqlHead="SELECT TERR,  YEAR,  WEEK#,  FECHNB,  FEGGNB,  DHCANB,  FEAADM,  FEGHNB,  DDAITX,  DDALTX,  DDARQT,  DDDPVA,  DHA3CD "
gsqlFrom="FROM WEB.WEEKLY "
gsqlWhere="FECHNB = " &presentuserid& " "
gsqlTail=""

gstrSQL = gSQLWhereAdd("")

%>

The " &presentuserid& " is a number field in my access db

If one of the users has more than one account and would like to see the account I have added
in(1,2,3) in the access db field and that shows the user data for departments 1, 2 and 3.

But for the admin I would like to see all.

I have tried putting an * but that does not work and the thin is that I cannot say in(1,2,3,4,5,etc.) because it could go over 5000 and access does not let me do that.

any ideas of how could I tackle this one?

thanks!!!
 
If the user is an admin, don't include a where clause at all.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi,
Add an IF test to check for the admin userid and, if that is the user, do not add any where clause to your sql.




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
so I could do something like this
Code:
    Dim presentuserid

presentuserid=rs("userid")

if presentuserid=00 then


strTableName="WEBSPA.WEEKLYSLS"
Session("OwnerID") = Session("_" & strTableName & "_OwnerID") ' to support older events and default values

strOriginalTableName="WEB.WEEKLY"

gPageSize=50

gstrOrderBy=""
if len(gstrOrderBy)>0 and lcase(mid(gstrOrderBy,1,8))<>"order by" then gstrOrderBy="order by " & gstrOrderBy
    


gsqlHead="SELECT TERR,  YEAR,  WEEK#,  FECHNB,  FEGGNB,  DHCANB,  FEAADM,  FEGHNB,  DDAITX,  DDALTX,  DDARQT,  DDDPVA,  DHA3CD "
gsqlFrom="FROM WEB.WEEKLY "
gsqlWhere=""
gsqlTail=""

gstrSQL = gSQLWhereAdd("")

else

    Dim presentuserid

presentuserid=rs("userid")


strTableName="WEBSPA.WEEKLYSLS"
Session("OwnerID") = Session("_" & strTableName & "_OwnerID") ' to support older events and default values

strOriginalTableName="WEB.WEEKLY"

gPageSize=50

gstrOrderBy=""
if len(gstrOrderBy)>0 and lcase(mid(gstrOrderBy,1,8))<>"order by" then gstrOrderBy="order by " & gstrOrderBy
    


gsqlHead="SELECT TERR,  YEAR,  WEEK#,  FECHNB,  FEGGNB,  DHCANB,  FEAADM,  FEGHNB,  DDAITX,  DDALTX,  DDARQT,  DDDPVA,  DHA3CD "
gsqlFrom="FROM WEB.WEEKLY "
gsqlWhere="FECHNB = " &presentuserid& " "
gsqlTail=""

gstrSQL = gSQLWhereAdd("")

end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top