| Author |
Topic |
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-12 : 05:42:47
|
I have the following Query which counts the no. of top priority calls for all our customers:SELECT Count(id) as pricnt from faultlog where (queueid=1 or queueid=2) and status<15 and priority=1 I want to adjust the code so on the summary table we can make it count for the specific customer that is logged in.... i.e. Company X- can see they have 2 priority calls and Company Y can see they have 0 priority calls.If that makes sense?The problem is the faultlog table only has a 'company' field which is varchar(254) -just the company name and no unique idetifierSo if company x is logged on i want the screen to show how many priority calls they have....Any ideas? |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-12 : 06:34:15
|
I think i need to add company= 'company x' to the end of the statement but change company x to something that can identify the company that is logged in at the time... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 08:04:48
|
pass company as a parameter likeSELECT Count(id) as pricnt from faultlog where (queueid=1 or queueid=2) and status<15 and priority=1 and company= @company then pass reqd value from front end as 'company x', 'company y' etc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-12 : 09:25:39
|
quote: Originally posted by visakh16 pass company as a parameter likeSELECT Count(id) as pricnt from faultlog where (queueid=1 or queueid=2) and status<15 and priority=1 and company= @company then pass reqd value from front end as 'company x', 'company y' etc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
what do you mean about the bit in bold mate? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 09:29:39
|
| that means based on what company logged in you grab the value at front end and pass it down to the shown query through the @company parameter------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-12 : 09:31:15
|
error message i get:mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: message: Must declare the scalar variable "@company". (severity 15) |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-12 : 09:31:58
|
quote: Originally posted by visakh16 that means based on what company logged in you grab the value at front end and pass it down to the shown query through the @company parameter------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
How do i do that?sorry for being dumb! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 09:38:24
|
quote: Originally posted by Jay87
quote: Originally posted by visakh16 that means based on what company logged in you grab the value at front end and pass it down to the shown query through the @company parameter------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
How do i do that?sorry for being dumb!
that depends on your front end. I've no idea what front end you're using------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-12 : 09:46:03
|
This is the code behind the login screen (sorry its abit long!)include 'header.htm';if (!isset($_POST['user'])){$_POST['user']=NULL;}if (!isset($_GET['err'])){$_GET['err']=NULL;}if ($_POST['user']!=NULL){ if ($_POST['user']=="" || $_POST['pass']==""){header("location: index.php?err=1");exit(0);} //Check for Contact Login first... include 'dbcon.php'; $result = mssql_fetch_array(mssql_query("SELECT id,(forename + ' ' + surname) as contact,company FROM contact WHERE username='" . $_POST['user'] . "' AND PWDCOMPARE('" . $_POST['pass'] . "',password)=1",$db)); //Check if the user is a customer if ($result!=NULL){ $_SESSION['user'] = $result['contact']; $_SESSION['guid'] = $result['id']; $_SESSION['level']=1; $_SESSION['rights']=3; $_SESSION['pfx'] = "C" . date('Y'); $_SESSION['conts'] = array ($result['id']); } else { //If not, Check Engineers list $ad = ldap_connect("ldap://" . getParam("ad_server")); if (ldap_bind($ad,getParam("domain") . "\\" . $_POST['user'],$_POST['pass'])) { //Search for charlton engineer (CNE) $attributes = array("cn","objectGUID","directReports"); $result = ldap_search($ad, getParam("engineers"), "(saMAccountName=" . $_POST['user'] . ")", $attributes); if (ldap_count_entries($ad,$result)==0) { //if not charlton engineer, are they a customer based engineer (CBE) $result = ldap_search($ad, getParam("offsite_eng"), "(saMAccountName=" . $_POST['user'] . ")", $attributes); if (ldap_count_entries($ad,$result)==0) { //no user found, reject logon echo "Cannot logon!"; exit(0); } //Set level to CBE $_SESSION['level']=3; } else { //Set level to CNE $_SESSION['level']=10; } //Save other engineers attributes to the session cookie $entry = ldap_get_entries($ad, $result); $single_entry = ldap_first_entry($ad, $result); $guid = ldap_get_values_len($ad, $single_entry, 'objectguid'); $_SESSION['user']=$entry[0]['cn'][0]; $_SESSION['guid']=convertGUID($guid[0]); $_SESSION['pfx'] = "C" . date('Y'); $_SESSION['conts']=array (); $_SESSION['rights'] = mssql_result(mssql_query("SELECT rightsmask FROM engineer WHERE id='" . $_SESSION['guid'] . "'",$db),0,0); $_SESSION['defsearch'] = mssql_result(mssql_query("SELECT defsearch FROM engineer WHERE id='" . $_SESSION['guid'] . "'",$db),0,0); $_SESSION['conts'] = split(",",mssql_result(mssql_query("SELECT customers FROM engineer WHERE id='" . $_SESSION['guid'] . "'",$db),0,0)); ldap_unbind($ad); } else { header("location: index.php?err=1"); exit(0); } } if (isset($_POST['callid'])){ header("location: calllist.php?id=" . $_POST['callid'] . "&pfx=" . $_POST['callpfx']); exit(0); } header("location: calllist.php" . $_SESSION['defsearch']); }?><form action='index.php' method='post'><? if (isset($_GET['callid'])){ echo "<input type='hidden' name='callid' value='" . $_GET['callid'] . "'/>";}?><? if (isset($_GET['callpfx'])){ echo "<input type='hidden' name='callpfx' value='" . $_GET['callpfx'] . "'/>";}?><table cellspacing=0 cellpadding=0 width=100% height=100%><tr><td valign=top align=center><img src='images/login.jpg' alt='Login'></td></tr> <tr><td> </td></tr> <tr ><td valign=top align=center> <table cellspacing=0 cellpadding=0 height=5 border=0 width=300><? if ($_GET['err']==1){echo " <tr><td align=center><font color=red>Incorrect Username or Password</td></tr>";echo " <tr><td> </td></tr>"; }?> <tr><th class='overhead_cell' style="border-right:0px;">Enter Credentials</th></tr> <tr><td class='std_disp_entry_btm'> <table cellpadding=5 cellspacing=0 width=100%> <tr><td align=right style="padding-right:5px;"><font face='Arial' size=2 color=909098><b>Username: </td><td><input onkeypress="if (window.event.keyCode==13)submit();" type='input' name='user'></td></tr> <tr><td align=right style="padding-right:5px;"><font face='Arial' size=2 color=909098><b>Password: </td><td><input onkeypress="if (window.event.keyCode==13)submit();" type='password' name='pass'></td></tr> </table> </td></tr> <tr><td> </td></tr> <tr><td colspan=2 align=center><button class=flat onclick="submit();">Login</button></td></tr> </table> </td></tr> <tr><td height=10> </td></tr> <tr valign=top height=100%><td align=center><font size=2>If you have forgotten your login details please send an email to:<br><a href='mailto:helpdesk@charltonnetworks.co.uk'>helpdesk@charltonnetworks.co.uk</a></td></tr> <tr valign=bottom><td align=right><font size=0.5>1.3</font></td></tr></table> |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 09:49:45
|
quote: Originally posted by Jay87 error message i get:mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: message: Must declare the scalar variable "@company". (severity 15)
you need to declare variable before you use it DECLARE @company varchar(100)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-12 : 10:13:48
|
quote: Originally posted by visakh16
quote: Originally posted by Jay87 error message i get:mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: message: Must declare the scalar variable "@company". (severity 15)
you need to declare variable before you use it DECLARE @company varchar(100)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
PHP Parse error: syntax error, unexpected '@', expecting '(' in /var/www/helpdesk-dev/summary.php on line 250 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 10:26:26
|
I dont know how do it in php but I've given works in t-sqlCREATE PROC GetCompanyCount@company varchar(100)ASSELECT Count(id) as pricnt from faultlog where (queueid=1 or queueid=2) and status<15 and priority=1 and company= @companyGOthen call it likeEXEC GetCompanyCount 'Company X' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-19 : 07:09:36
|
I am still totally stuck on this...currently have the following sql server code:DECLARE @company varchar(254) SELECT Count(id) as pricustcnt from faultlog where (queueid=1 or queueid=2) and status<15 and priority=1 and company= @company this is how i run it on the page:$query = mssql_query("DECLARE @company varchar(254) SELECT Count(id) as pricustcnt from faultlog where (queueid=1 or queueid=2) and status<15 and priority=1 and company= @company", $db); $PriorityCustCount=mssql_result($query,0,'pricustcnt'); which always returns 0 no matter who is logged in...If i log in with a company who have 1 priority call, it stills shows 0....very frustrated! Any ideas? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-19 : 07:24:31
|
| Did you supply value for @company?MadhivananFailing to plan is Planning to fail |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-19 : 07:30:16
|
| Not sure what that means?The code i added above is the only code i've used to try and get it to work, so probably not! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-19 : 07:33:16
|
quote: Originally posted by Jay87 Not sure what that means?The code i added above is the only code i've used to try and get it to work, so probably not!
@company is a parameter in your code ie. like a place holder through which you pass actual value you got from application. Madhi is asking if you've done that (specified the value from application for that company place holder)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-19 : 07:33:46
|
| You should use stored procedure with input parameter and supply value for it when executingMadhivananFailing to plan is Planning to fail |
 |
|
|
Jay87
Starting Member
41 Posts |
Posted - 2010-02-19 : 07:43:10
|
quote: Originally posted by visakh16
quote: Originally posted by Jay87 Not sure what that means?The code i added above is the only code i've used to try and get it to work, so probably not!
@company is a parameter in your code ie. like a place holder through which you pass actual value you got from application. Madhi is asking if you've done that (specified the value from application for that company place holder)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
No i haven't, how would i do that? |
 |
|
|
|