Ask a Question related to ASP Database, Design and Development.
-
J P Singh #1
SQL Query - Help
Can someone please help me with query.
We are using this query in one of our asp pages. As I didn't write this
query in the firstplace I am finding it hard to add the two conditions I
want.
I want to add two conditions in the where clause like the one below
EmpProfile.Left = False and Holidayrequest.Status = 3 to the overall
condition
sqlstr = "SELECT [FirstName] & ' ' & [LastName] AS
Expr1,IIf(DateSerial(Year([fdate]),Month([fdate]),1)<DateSerial(" & selyear
& "," & selmonth & ",1),1,CInt(Day([FDate]))) AS StartDay, IIf(
DateSerial(Year([TDate]),Month([TDate]),1)>DateSerial(" & selyear & "," &
selmonth & ",1),Day(DateSerial(" & selyear & "," & selmonth &
",0))+CInt(Day([tDate])),CInt(Day([tDate]))) AS EndDay,
HolidayRequests.FDate, HolidayRequests.TDate, CInt(Month([FDate])) AS
StartMonth, CInt(Month([tDate])) AS EndMonth "
sqlstr = sqlstr & "FROM EmpProfile INNER JOIN HolidayRequests ON
EmpProfile.EmployeeNumber = HolidayRequests.Userid "
sqlstr = sqlstr & "WHERE (((Month([FDate]))=" & selmonth & ") AND
((Year([FDate]))=" & selyear & ") AND EmpProfile.Department='" & seldept &
"') OR (((Month([FDate]))="
The table structure is as below
Empprofile
EmployeeNumber (Number)
FirstName (Text)
LastName (Text)
Department (Text)
Left (Boolean)
HolidayRequests
UsedId (number)
Fdate (Date)
Tdate (Date)
Status (Number)
J P Singh Guest
-
Query of Queries on query New type query
In CF5 we have a page that creates a query, using queryNew and querySetCell and the like, we then used dbtype="query" and gave it's name so we could... -
query of query throwing weird exception
One workaround: I had added rows to a cfsearch query, and set a numeric value in custom1 field that that query provides. A query of queries... -
Convert a query to a list, or find an item in a query
Hi All, I am using CFPOP to retrieve mail from a server, then delete each message after I retrieve it. What I want to do is to check that I don;t... -
CAML Query: Multiple Query Fields Issue
I need to Create a CAML Query Dynamically with VB to a Sharepoint WebService GetListItems Method. The User Could Select 1 to X Number of IDs... -
BCP query out executed by xp_cmdshell works fine from query analyzer but fails from VB Component
Hi all, I have a stored procedure which returns a vast number of record and i have to write the output into a csv file. I'm using BCP utility to... -
Ray at #2
Re: SQL Query - Help
Good lord.
modified snippet:
sqlstr = sqlstr & "WHERE (((Month([FDate]))=" & selmonth & ") AND
((Year([FDate]))=" & selyear & ") AND EmpProfile.Department='" & seldept &
"') OR (((Month([FDate]))=" ThereShouldBeAVariableHere & " AND
(EmpProfile.Left = FALSE AND Holidayrequests.status=3)"
Ray at work
"J P Singh" <noemail@asIhatespam> wrote in message
news:uE3dkeWcDHA.2820@tk2msftngp13.phx.gbl...selyear> Can someone please help me with query.
>
> We are using this query in one of our asp pages. As I didn't write this
> query in the firstplace I am finding it hard to add the two conditions I
> want.
>
> I want to add two conditions in the where clause like the one below
>
> EmpProfile.Left = False and Holidayrequest.Status = 3 to the overall
> condition
>
>
> sqlstr = "SELECT [FirstName] & ' ' & [LastName] AS
> Expr1,IIf(DateSerial(Year([fdate]),Month([fdate]),1)<DateSerial(" &&> & "," & selmonth & ",1),1,CInt(Day([FDate]))) AS StartDay, IIf(
> DateSerial(Year([TDate]),Month([TDate]),1)>DateSerial(" & selyear & "," &
> selmonth & ",1),Day(DateSerial(" & selyear & "," & selmonth &
> ",0))+CInt(Day([tDate])),CInt(Day([tDate]))) AS EndDay,
> HolidayRequests.FDate, HolidayRequests.TDate, CInt(Month([FDate])) AS
> StartMonth, CInt(Month([tDate])) AS EndMonth "
>
> sqlstr = sqlstr & "FROM EmpProfile INNER JOIN HolidayRequests ON
> EmpProfile.EmployeeNumber = HolidayRequests.Userid "
>
> sqlstr = sqlstr & "WHERE (((Month([FDate]))=" & selmonth & ") AND
> ((Year([FDate]))=" & selyear & ") AND EmpProfile.Department='" & seldept> "') OR (((Month([FDate]))="
>
>
> The table structure is as below
>
> Empprofile
>
> EmployeeNumber (Number)
> FirstName (Text)
> LastName (Text)
> Department (Text)
> Left (Boolean)
>
> HolidayRequests
>
> UsedId (number)
> Fdate (Date)
> Tdate (Date)
> Status (Number)
>
>
Ray at Guest
-
CoffeeCup #3
SQL query - HELP
I?m trying to get a SQL query to return data from 3 tables.
I need all the data in my tbl_producs table to be returned, the other two
table are linked but some fields are empty i.e. product 1 might only have a
cat3ID and not a brandID. Product 2 might have both etc.
I keep getting a ? ?Syntax error (missing operator) in query expression
'tbl_category_3.cat3ID = tbl_products.cat3ID RIGHT JOIN tbl_brands ON
tbl_brands.brandID = tbl_products.brandID'. ?
Here?s my query ?
<cfquery datasource="#REQUEST.DataSource#" name="ProdList">
SELECT tbl_products.productsID,
tbl_products.cat3ID,
tbl_products.branchID,
tbl_products.brandID,
tbl_products.prod_name,
tbl_category_3.cat3ID,
tbl_category_3.cat3_name,
tbl_brands.brandID,
tbl_brands.brand_name
FROM tbl_category_3
LEFT JOIN tbl_products
ON tbl_category_3.cat3ID = tbl_products.cat3ID
RIGHT JOIN tbl_brands
ON tbl_brands.brandID = tbl_products.brandID
WHERE tbl_products.branchID = '#branchID#'
ORDER BY prod_name
</cfquery>
Any help is greatly appreciated
CoffeeCup Guest
-
-
-
mxstu #6
Re: SQL query - HELP
I think Access requires parenthesis around each JOIN in the FROM statement I don't have Access on this machine so I cannot give you the correct syntax.
mxstu Guest
-
CoffeeCup #7
Re: SQL query - HELP
Thanks "mxstu"
I will give it a go see what happens...
CoffeeCup Guest
-
mxstu #8
Re: SQL query - HELP
You may want to use the query builder in Access just to give you an idea of the syntax. I wouldn't use the Access generated code for your cfquery though... it's usually quite ugly ;-)
mxstu Guest
-
CoffeeCup #9
Re: SQL query - HELP
I tried the query builder in access.
It returns the data, but only the recordes that have data in all filed. So
catID fields where there is not data it does not return the data???
Here's the query..
<cfquery datasource="#REQUEST.DataSource#" name="ProdList">
SELECT tbl_category_2.cat2ID AS tbl_category_2_cat2ID,
tbl_category_2.cat2_name,
tbl_brands.brandID AS tbl_brands_brandID,
tbl_brands.brand_name,
tbl_category_3.cat3ID AS tbl_category_3_cat3ID,
tbl_category_3.cat3_name,
tbl_products.productsID,
tbl_products.cat2ID AS tbl_products_cat2ID,
tbl_products.cat3ID AS tbl_products_cat3ID,
tbl_products.branchID, tbl_products.brandID AS tbl_products_brandID,
tbl_products.prod_name
FROM tbl_category_3
INNER JOIN (tbl_category_2 INNER JOIN (tbl_brands INNER JOIN tbl_products ON
tbl_brands.brandID = tbl_products.brandID) ON tbl_category_2.cat2ID =
tbl_products.cat2ID) ON tbl_category_3.cat3ID = tbl_brands.cat3ID
WHERE tbl_products.branchID = '#branchID#'
ORDER BY prod_name
</cfquery>
CoffeeCup Guest
-
mxstu #10
Re: SQL query - HELP
That's because you're using all INNER joins. Now that you understand what parenthesis are required, uou need to change the joins to the approriate type.
mxstu Guest
-
CoffeeCup #11
Re: SQL query - HELP
Thanks "mxstu"
Changed the joins to right joins and it works.
By the way, if i change the database to SQL will i need to remover the parenthesis?
Thank for your help
CoffeeCup Guest
-
mxstu #12
Re: SQL query - HELP
If you mean sql server, then no you should not *have* to remove the parenthesis, but it would be cleaner if you did.
mxstu Guest
-



Reply With Quote

