I'm using this to populate some templates I'm using.
I need to add a parameter for the query:
SELECT tblArticle.ArticleCatID, tblArticle.ArticleID, tblArticle.ArticleText, tblArticle.ArticleTitle, tblArticle.Author, tblArticle.ShortDesc, tblArticle.WebSiteID,
tblWebSite.SiteURL, tblWebSite.PageRank
FROM tblArticle INNER JOIN
tblWebSite ON tblArticle.WebSiteID = tblWebSite.WebSiteID
WHERE (tblArticle.ArticleCatID = @articlecatid) and tblArticle.Active=@active
This is from a tableadapter. How to I get the True value passed into this thing? When an article is initially saved, the active value is set to false until the article is reviewed. Once everything is ok, then the status is set to actve. So, although everything is sitting there in the table for the article, the directory will not pull it up with other search results already approved.
I have to create a stored procedure where the criteria is: "All", specific value and, all except one value so far this is what I have:@Status varchar (50) -- as parameter from a dropdown boxDECLARE @NewStatus varchar(50) SET @NewStatus = CASE WHEN @Status ='All' AND @Status <> 'All but closed' THEN '%' WHEN @Status <>'All' AND @Status <> 'All but closed' THEN @Status END
and in the stored procedure
.........
WHERE Status like @NewStatus I am a little confused as to how could I return all values except those that have the value "Closed" Thanks.
Hi,Is it possible to create a query with an IIf Function but using a parameter in the expression?This is what I'm trying to do, except it doesn't work:SELECT Related_Area_Id, Course_Code, Course_Public_Title, Course_Level, Course_WBLTTG_OnlyFROM dbo.CourseWHERE (Related_Area_Id = @CurriculumArea) AND (Course_Level = @CourseLevel) AND (Course_WBLTTG_Only = IIf(@Apprenticeship = True, 1, 0)) Are there any other solutions?Thanks
I am working with a Report Designer where I am using SQL to get data which user wants to see so I am using parameters.In my SQL database, name and surname columns can not be NULL, but nick can be NULL.The problem is with 3rd parameter ${Nick}. I need to do some condition like this: if user lefts 3rd parameter empty, it should select people where table.nick is NULL, otherwise it should select people by entered nick. But I do not know how to rework my query.
Hi,The following parameter query SQL statement on a sql analyzer gives theerror message given below.Select * from contact where cus_cust_no = ?[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax errorThanks*** Sent via Devdex http://www.devdex.com ***Don't just participate in USENET...get rewarded for it!
I am new the asp.net. I have written the following code and cannot get it to read from my text boxes to assign the values to the parameters. When I use a fixed value in a string variable and set the parameter to it, I can make it work, but not from the text boxes. Any help is greatly appreciated. Thanks
Sub btnUpdate_Click(ByVal s As Object, ByVal e As EventArgs)
' Connect to DB Dim conInventory As SqlConnection Dim cmdUpdate As SqlCommand Dim strCommand As String Dim test As String test = "hello" 'my attempt to test the sql parameter strCommand = ""
conInventory = New SqlConnection("server=server;uid=id;pwd=pwd;database=db")
cmdUpdate = New SqlCommand("Update [tw48_inventory] Set [Date]=@Date", conInventory) cmdUpdate.Parameters.Add(New SqlParameter("@Date", SqlDbType.VarChar, 50)) cmdUpdate.Parameters("@Date").Value = test 'cmdUpdate.Parameters.Add(New SqlParameter("@Date", test)) 'works with constant string value conInventory.Open() cmdUpdate.ExecuteNonQuery()
conInventory.Close()
End Sub Sub Page_Load() ' Connect to DB Dim conInventory As SqlConnection Dim cmdSelect As SqlCommand Dim dtrReader As SqlDataReader
conInventory = New SqlConnection("server=server;uid=id;pwd=pwd;database=db") conInventory.Open()
cmdSelect = New SqlCommand("Select * From tw48_inventory", conInventory) dtrReader = cmdSelect.ExecuteReader
hi,i can do"select * from products where name = @name" kind of statements in query builder but"select * from products where name LIKE @name" dosen't work!" any ideas? i'm using sql server express. thanks
Hello, I want to select all the customerIDs where an email address exists. Easy: select customerid from customers where emailaddress = @emailaddress Now I want to use the resulted customerIDs from the above query as a parameter to select all the email addresses with emailstatus equal to 3. How do I create this type of while statement in a stored procedure? I prefer to not create a temporary table. My idea was to do it like this: select emailaddress from emailaddresseswhere emailstatus = 3 and customerid = (select customerid from customers where emailaddress = @emailaddress) This doesn't seems to work. I get the error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. thanks
Im struggling with this, I think its probably quite simple. I have a table that looks like this:
RecordId PictureId KeywordId
111 212 313 421 522 623 725 817 932 1044
I want to be able to run a query for a distinct listing of PictureIds that have KeywordId=1 and Keyword=2. When trying a simple query like:select PictureId from PicturesKeywords where (keywordid=1 and keywordid=2) group by PictureId It obviously returns nothing. What am I doing wrong?
I have the following function that is run when a person enters a value, "Cell", in an access form. I am trying to execute the pass through query in SQL Server but i keep getting the following message:
"The microsoft jet database engine cannot find the input table or query 'CellDefs'. Make sure it exists and its name is spelt correctly."
There is nothing wrong with the table name. I cant understand what the problem is ?????
Can anyone tell me how to execute a query that passes a parameter from access to Sql server.
Thanks, Ruaidhri
Public Function GetData(Cell As String) Dim dbsCurrent As Database Dim qd1 As QueryDef Dim SQL As String Dim rs As Recordset Dim qdf As QueryDef Set dbsCurrent = CurrentDb
Set qd1 = dbsCurrent.CreateQueryDef("") With qd1 .Connect = "ODBC;DSN=MISChief;SERVER=Janeway;UID=sa;PWD=;DATA BASE=MIS" SQL = "" SQL = SQL + "INSERT INTO TableX SELECT A.Name AS CellCode, C.FinderNumber" SQL = SQL + "FROM (CellDefs AS A INNER JOIN Calls AS B ON " SQL = SQL + "A.CellDef_id = B.CellDef_id) INNER JOIN Finders AS C ON " SQL = SQL + "B.Finders_id = C.Finders_id " SQL = SQL + "WHERE A.Name LIKE '" & Cell & "' " SQL = SQL + "ORDER BY C.FinderNumber" .ReturnsRecords = False .ODBCTimeout = 2400
dbsCurrent.Execute (SQL) End With dbsCurrent.Close End Function
I just migrated a stand alone MSAccess2003 .mdb to an .adp Access Data Project. In the former .mdb I had a parameter query to search for a portion of a 17 character part number, primarily the 2 grouping of 4 digits as in (00-0000-XXXX-0-00). In Access the query was written as
LIKE “*”&[Enter a portion of the part number]&”*”
Then we ported to a web based portal using MSAccess’s DAP (data access pages) and I was told due to ADO vs DAO the query had to be rewritten using the % symbol as in
LIKE “%”&[Enter a portion of the part number]&”%”
So far so good. However with the migration to a SQL Server and ANSI-92 compatible wildcard characters this has changed. The new query looks like this
LIKE @Enter_a_portion_of_the_part_number +n’%’
The problem I am having is the prompt for data entry works but the wildcard will only return matching values from the first digit place holder. Some of the books I have read said to use the Under Score character to move the search criteria to the section I want to search which would be starting with the 9th character (00-0000-XXXX-0-00) as in
LIKE @Enter_a_portion_of_the_part_number +n’________%
However the Under Score only works with Alpha Characters and not Numeric.
So how do I write a SQL Server Query to perform like it did in Access?
I am trying to get a DTS package to work w/ an ActiveX box to prompt user for a Date. I am pulling data out of a table into an Excel spreadsheet. The date keyed by user gets passed into parameter ? in query. I have assigned a global variable to package also. The DTS package executes fine but no row appear in the Excel spreadsheet. I'm guessing that the date keyed in input box does not match date from database for some reason. I have tried multiple ways of inputing date in input box and have tried different case/convert statements in query. I know the dates are there because I can hard code in the date as '2005-10-03' and it works. Just can't get it work by feeding in user input into where clause. Does anyone know what I'm missing.
I have a much more complex query but here's the simple one I'm using just to try to get it to work.
select consumerid, convert(char(10),servicedatefrom, 101) 'Date of Service', convert(char(10),updatedate, 101) 'Update Date' from tbl_cs_sv_service where convert(char(10),updatedate, 101) = ?
Here's the ActiveX script to prompt user for date input
'********************************************************************** ' Visual Basic ActiveX Script '************************************************************************ Function Main()
I've a query which i need to run as Parameter Driven, where SQL asks me for an input let's say for a Date in a query. is this possible in SQL SERVER like in Oracle, if so can anybody suggest me where do i look at.
here's my quer.
SELECT * FROM TABLE WHERE DATE > '1/01/2008'
instead of 1/01/2008 Sql Prompts me to enter my own Date and display the result.
Hi All,I have a stored proc which looks like this.Create ....(@id int,@ud int,@td int=0)if @td=0select bkah from asdf where id=@id and ud=@udelseselect bkah from asdf where id=@id and ud=@ud and td=@td---------------------------------I am wondering if i could replace if condition with the following lineselect bkah from asdf where id=@id and ud=@udand ( @td<>0 and td>@td )IS sql server 2000 smart enough not to use the td>@td in the query if@td is 0Thanks all
We're using RS2005 and I have the following question:
I have two report parameters that populated by a query within RS2005 and that works fine. Based on what I selected for the two report parameters I need to use these values to retrieve my Client's Name and paste on top of report in the header section of the report. I'm new at working with RS2005 but it appears to be hanging for some reason.
This is what I do to attempt to get the Client's Name. I created two individual datasets and populate with a query within RS2005. I created a third dataset and create parameters @PCMR, @PACCTNUM in the edit dataset section. I use parameters @PCMR and @PACCTNUM in WHERE clause of SQL statement in third dataset. I hope what I'm saying is making sense.
i'm trying to perform a query against a db2 database like this:
SELECT ... FROM ... WHERE (field IN (?))
Then i let reporting services pass the parameter to the report. When i try to preview the report, i get the following error:
An error occurred during local report processing, An error has occured during report processing, Cannot add multi value query parameter '?' for data set ... because it is not supported by the data extension
But when i type the query like this
SELECT ... FROM ... WHERE (field IN ('value1','value2'))
it executes flawlessly.
I am using the IBM ole db driver for db2 if that matters
What needs to be done to allow a user to input data in a "From query report parameter"?
The "From query" option was used to show all possible selections the user can do but what if the user would now like to select for partial key...i.e.: like '%tss%'
I would like to avoid the Multi-Value parameter option.
NOTE: The report is done through Microsoft Visual Studio / RDL.
I've only just starting working with RSS2005. I've started designing basic reports that pulls info from our HEAT DB (incident/change logging system).
One of the report requirements is to be able to pull reports for calls that were logged for specific day/date, using the calllog.recvddate field in the HEAT DB.
What i would like to know is how do i do this ? i.e. how do i setup the date query parameter so that the user can select a date from the calender picker that returns all calls logged for the selected date ? How do i link the date parameter to the calllog.recdvddate field ?
I posted this question on the Analysis Services forum ( http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1087288&SiteID=1 ) and Irina asked me to post it over here to get an answer.
I'm trying to run an MDX query against SSAS2005 with a parameter. It works fine with ADOMD.NET, but I can't get it to work using OleDb. (I have to use OleDb because of limitations of the calling application.) Is this possible?
The following code works: //using Microsoft.AnalysisServices.AdomdClient;
string MDX = "with member [Measures].[Test] as Str(@Param1) " + "SELECT [Measures].[Test] on 0, " + "[Product].[Category].[Category].Members on 1 " + "from [Adventure Works]";
AdomdConnection conn = new AdomdConnection("Provider=MSOLAP.3;Data Source=localhost;Initial Catalog=Adventure Works DW;Integrated Security=SSPI;Persist Security Info=false;"); conn.Open(); AdomdCommand cmd = new AdomdCommand(MDX, conn); cmd.Parameters.Add("Param1", "abcde"); System.Data.DataSet ds = new System.Data.DataSet(); AdomdDataAdapter adp = new AdomdDataAdapter(cmd); adp.Fill(ds); Console.WriteLine(ds.Tables[0].Rows[0][1]); conn.Close();
The following code fails: //using System.Data.OleDb; string MDX = "with member [Measures].[Test] as Str(@Param1) " + "SELECT [Measures].[Test] on 0, " + "[Product].[Category].[Category].Members on 1 " + "from [Adventure Works]"; OleDbConnection conn = new OleDbConnection("Provider=MSOLAP.3;Data Source=localhost;Initial Catalog=Adventure Works DW;Integrated Security=SSPI;Persist Security Info=false;"); conn.Open(); OleDbCommand cmd = new OleDbCommand(MDX, conn); cmd.Parameters.AddWithValue("Param1", "abcde"); //changing it to @Param1 doesn't help System.Data.DataSet ds = new System.Data.DataSet(); OleDbDataAdapter adp = new OleDbDataAdapter(cmd); adp.Fill(ds); //produces error: "The following system error occurred: The parameter is incorrect. . Error Code = 0x80070057, External Code = 0x00000000:." Console.WriteLine(ds.Tables[0].Rows[0][1]); conn.Close();
Hi, I have a little problem with a SqlDataSource. A table in my database has an ID collumn, which is an integer auto-increment. The datasource has a SelectQuery with an [ID] parameter, which it retrieves from the querystring. I want the DataSource to return all rows when no querystring parameter is passed, and when an ID is given via the querystring, a 'WHERE' clause in the SelectQuery would return only certain records. However, suppose I have the following query: SELECT * FROM SomeTable WHERE ([ID] = @ID) When I bind @ID to the QueryString with '*' as DefaultValue, it throws an exception saying it can't convert '*' to a smallint, which makes sense. I haven't got a clue how to solve this, except for using different DataSources based on the presence of the querystring parameter. Any idea's?
Hi all, I am using the below parameterized query and get an error while executing it....can anyone please spot the error. Any help will be appreciated. I have gone cross-eyed now looking at it all day. The error I get it isParameterized Query '(@Re_UK_Eligible nvarchar(4000),@Re_Aus_Eligible nvarchar(33),@R' expects parameter @Re_JobType_Temp, which was not supplied. sqlStmt = "UPDATE Re_Users SET Re_UK_Eligible=@Re_UK_Eligible,Re_Aus_Eligible=@Re_Aus_Eligible,Re_Can_Eligible=@Re_Can_Eligible,Re_USA_Eligible=@Re_USA_Eligible,Re_Address1=@Re_Address1,Re_Address2=@Re_Address2,Re_Address3=@Re_Address3,Re_City=@Re_City,Re_Postcode=@Re_Postcode,Re_Country=@Re_Country,Re_Homephone=@Re_Homephone,Re_Mobile=@Re_Mobile,Re_JobType_Per=@Re_JobType_Per,Re_JobType_Temp=@Re_JobType_Temp,Re_JobType_Con=@Re_JobType_Con,Re_Hours_Full=@Re_Hours_Full,Re_Hours_Part=@Re_Hours_Part,Re_Sector=@Re_Sector,Re_StepTwoDone=1 WHERE Re_UserCount=" + Session["ReUserIdentity"]; cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ReConnectionString"].ConnectionString); cmd = new SqlCommand(sqlStmt, cn); cmd.CommandType = CommandType.Text;
//Insert UK if (chkUK.Checked == false) { cmd.Parameters.Add(new SqlParameter("@Re_UK_Eligible", DBNull.Value)); } if ((chkUK.Checked == true) && (UKRadioButtonList.SelectedIndex > -1)) { cmd.Parameters.Add(new SqlParameter("@Re_UK_Eligible", UKRadioButtonList.SelectedItem.Text)); }
//Insert AUS if (chkAUS.Checked == false) { cmd.Parameters.Add(new SqlParameter("@Re_Aus_Eligible", DBNull.Value)); } if ((chkAUS.Checked == true) && (AUSRadioButtonList.SelectedIndex > -1)) { cmd.Parameters.Add(new SqlParameter("@Re_Aus_Eligible", AUSRadioButtonList.SelectedItem.Text)); }
//Insert CAN if ((chkCAN.Checked == false)) { cmd.Parameters.Add(new SqlParameter("@Re_Can_Eligible", DBNull.Value)); } if ((chkCAN.Checked == true) && (CANRadioButtonList.SelectedIndex > -1)) { cmd.Parameters.Add(new SqlParameter("@Re_Can_Eligible", CANRadioButtonList.SelectedItem.Text)); }
//Insert USA if (chkUSA.Checked == false) { cmd.Parameters.Add(new SqlParameter("@Re_USA_Eligible", DBNull.Value)); } if ((chkUSA.Checked == true) && (USARadioButtonList.SelectedIndex > -1)) { cmd.Parameters.Add(new SqlParameter("@Re_USA_Eligible", USARadioButtonList.SelectedItem.Text)); }
Hello, I am currently using vs2005 with sql2000 and have a parameter query getting records form my sql2000 db.
'Load existing data to textboxes for editingDim strSQL1 As String = "SELECT id, LogDate, LogTime, LogDD, StatDD, LogEvent FROM DEMO_DailyOccurrence WHERE completed = 0 AND RecordIdentify = @strOutdate ORDER BY id ASC "Dim scnnNW1 As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("SQLconnection"))Dim scmd1 As New SqlCommand(strSQL1, scnnNW1)With scmd1.Parameters.Add(New SqlParameter("@strOutdate", SqlDbType.DateTime)).Value = strOutdate1End WithDim sda1 As New SqlDataAdapter(scmd1)Dim ds1 As New Data.DataSetTrysda1.Fill(ds1)Catch ex As ExceptionEnd Try
strOutdate1 is a date and has been tested and proven to be OK. When I run the same code against my sql2005 db, the query returns nothing. Do I have to handle something differently for sql2005.
just getting started with my first db driven web project... I am using a MySql database with membership and roles and got that working fine. I have tables containing details of courses that users are enrolled on etc. and want to display a list of courses for the user that is signed in, so he can continue lessons on the one of his choice. How do I pass the users name to the database query for a DataList control. So far I have tried lots of variations of the following: <asp:SqlDataSource ID="dsCourses" runat="server" ConnectionString="<%$ ConnectionStrings:xxx %>" ProviderName="<%$ ConnectionStrings:xxx.ProviderName %>" SelectCommand="SELECT c.CourseName FROM courses c, enrolments e WHERE c.CourseID=e.CourseID AND e.Username='<% =User.Identity.Name %>'"></asp:SqlDataSource> <asp:DataList ID="DataList1" runat="server" DataSourceID="dsCourses"> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="Lesson.aspx">'<%# Eval("CourseName") %>'</asp:HyperLink><br /> </ItemTemplate></asp:DataList> </p> However, the <% =User.Identity.Name %> doesn't work here (but it does elsewhere on the page) - not sure why?? The code works fine if I hard code a user name into the select statement. Suggestions pleeeeeese!!
I am trying to return an ouput parameter from my query. I have tested the stored proceedure extensivly within the SQL Management Studio, and I know it works fine, so that means the error is somewhere within my code, but for the life of my I cant figure where. Here is my stored proc: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go
-- ============================================= -- Author:Name -- Create date: -- Description: -- ============================================= ALTER PROCEDURE [dbo].[tblSiteVisits_FindOfficerName] @VisitID int, @OfficerName varchar(100) output AS BEGIN -- Variables Declare @OfficerID int --Declare @OfficerName varchar(100) -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; Select @OfficerID = (Select top 1 OfficerID from tblSiteVisitOfficers Where VisitID = @VisitID)
IF (@OfficerID Is Null) BEGIN -- Get the None Registered Officer Select @OfficerName = (Select top 1 OfficerOther from dbo.tblSiteVisitOfficers Where VisitID = @VisitID) print 'Got unregistered Officer ' + @OfficerName END ELSE BEGIN -- Get the Registered Officer Select @OfficerName = (Select OfficerFName + ' ' + OfficerLname from dbo.tblOfficers Where OfficerID = @OfficerID) print 'Got Registered Officer ' + @OfficerName END END
And here is the code I am using to access this proceedure:1 Dim blah As String 2 Dim conn2 As New SqlConnection() 3 Dim cmd2 As New SqlCommand() 4 conn2.ConnectionString = _ConnString 5 cmd2.Connection = conn2 6 cmd2.CommandType = CommandType.StoredProcedure 7 cmd2.CommandText = "dbo.tblSiteVisits_FindOfficerName" 8 9 cmd.Parameters.AddWithValue("@VisitID", Convert.ToInt32(row("VisitID"))) 10 cmd.Parameters.Add("@OfficerName", SqlDbType.VarChar, 100) 11 cmd.Parameters("@OfficerName").Direction = ParameterDirection.Output 12 Try 13 conn.Open() 14 cmd.ExecuteNonQuery() 15 blah = cmd.Parameters("@OfficerName").Value.ToString() 16 17 Catch ex As Exception 18 Throw ex 19 Finally 20 conn.Close() 21 End Try 22
However there I never recieve the output value, and because of the way my database is structures, there is no possible way, that there is no output value.If anyone can help, that would be great, kind regards.
Is there a way to pass the column name as a query parameter?? If I use '@Question', like below, I get an error. If I change it to the actual name of the column 'Question1', it works fine. However, I need it to be dynamic so I can pass the column name [Question1, Question2, Question3, etc...] in and not have to define this for each question.
Doesn't Work!!
Code:
SELECT
1.0 * SUM(CASE WHEN @ColumnName > 1 THEN 1 ELSE 0 END) / COUNT(*) AS 'Good', 1.0 * SUM(CASE WHEN @ColumnName = 0 THEN 1 ELSE 0 END)/ COUNT(*) AS 'OK', 1.0 * SUM(CASE WHEN @ColumnName < 0 THEN 1 ELSE 0 END) / COUNT(*) AS 'Poor'
FROM tableA AS A INNER JOIN tableB AS B ON A.SessionID = B.SessionID
WHERE (A.SurveyID = @SurveyID) AND (A.SubmitDate BETWEEN @BeginDate AND @EndDate)
Works, but I need to pass in the column name dynamically.
Code:
SELECT
1.0 * SUM(CASE WHEN Question1 > 1 THEN 1 ELSE 0 END) / COUNT(*) AS 'Good', 1.0 * SUM(CASE WHEN Question1 = 0 THEN 1 ELSE 0 END)/ COUNT(*) AS 'OK', 1.0 * SUM(CASE WHEN Question1 < 0 THEN 1 ELSE 0 END) / COUNT(*) AS 'Poor'
FROM tableA AS A INNER JOIN tableB AS B ON A.SessionID = B.SessionID
WHERE (A.SurveyID = @SurveyID) AND (A.SubmitDate BETWEEN @BeginDate AND @EndDate)
how can I query the plotted shift sched of employees for a particular day? like I would like to know what shift the employees were scheduled from day1 to 15 of May 2008? the days that I would like to query would be dynamic so it can be day1 to 15 or day3 to day5 or just day20...
I have to build a query and I am not sure how to build it.
Our data has providers with different products. We have an “DGH” product and a “PRM”. I need to find the provider that don’t have both. Its sounds very simple, but I am having an awful time figuring it out. Sometimes I get a record that has both products, it is probably how my where clause is working.
Anyway, here is an example of what I don’t want in my records because this is good. It has a DGH and PRM.
pro_pcs pro_lname pro_fname prop_prd pro_tax1 pro_addr100018791 Smith John DGH 12345868 Kiem ST 00018791 Smith John PRM 12345868 Keim ST
I would want to see this one because there only a DGH and it need to have a PRM product.
pro_pcspro_lname pro_fname prop_prd pro_tax1 pro_addr1 00018791 Rubin SamDGH2345868 Kiem ST
I came up with this below and it seems to be working. The only thing is, I now have to make this so people can add a parameter on the pro_tax1 to see the different records. Is there a better way to do this or how can I use what I have below and add a parameter too it.
Select pro_pcs, pro_lname, pro_fname, pro_addr1 from #ALLProducts Where pro_tax1 = '12345868' and prop_prd = 'DGH'
except
Select pro_pcs, pro_lname, pro_fname, pro_addr1 from #ALLProducts Where pro_tax1 = '12345868'and prop_prd = 'PRM'
My end result will be a query with about six parameters total. But for right now I am trying to one by one for testing purposes. This is my first SQl project. All of my information goes into an Access DB. I am basically creating a search page with parameters for the employees to use to search for data. I need the query to work if all parameters, or combinations of parameters, or just one parameter is chosen. I started with one and got to three but now I'm stuck. My first two parameters are dates, so the data can be chosen by date range, and the second is location id. If I choose date range by itself it works, If I choose location id by itself it works, but If I choose both it doesn't work. Instead of filtering it gives me everything and I have a statement for it. Can someone please help me and tell me what am I not doing right. Here is my code;
SELECT * FROM ASFdata WHERE (ASFdata.reportlocid = <cfqueryparam value="#Form.reportlocid#"> AND <cfqueryparam value="#Form.datefield#"> <> datefield AND <cfqueryparam value="#Form.datefield2#"> <> datefield) OR (ASFdata.datefield BETWEEN <cfqueryparam value="#Form.datefield#"> AND <cfqueryparam value="#Form.datefield2#"> AND NOT <cfqueryparam value="#Form.reportlocid#"> = reportlocid ) OR (ASFdata.datefield BETWEEN <cfqueryparam value="#Form.datefield#"> AND <cfqueryparam value="#Form.datefield2#"> AND ASFdata.reportlocid = <cfqueryparam value="#Form.reportlocid#">)