Prompt comes up when running report - report

I have created a report from the following query
SELECT TasksEntries.Project, TasksEntries.Task, Sum(TimeTracker.WorkHours) AS
TotalHours
FROM TasksEntries INNER JOIN TimeTracker
ON (TasksEntries.EmployeeId = TimeTracker.EmployeeId) AND (TasksEntries.TaskID
= TimeTracker.TaskId)
GROUP BY TasksEntries.Project, TasksEntries.Task;
The start and end dates are captured from a form and passed like shown below. WorkDate is a column in the TimeTracker table and is not present in any other table.
strWhere = "WorkDate BETWEEN #" & txtMgrRptStartDate & "# AND #" &
txtMgrRptEndDate & "#"
DoCmd.OpenReport "rptTotalProjectHours", acViewPreview,
"qryTotalProjectHours", strWhere, acWindowNormal
When the report is invoked, I get a box where it says
"Enter parameter value" for Workdate.. I am unsure why I get that.
The query runs fine when I run it separately with the start and end dates hard coded in there. The problem seems to occur only when it is passed through the docmd.openreport. Can someone help me get to the bottom of this? When passing the WorkDate thru the OpenReport, is it mandatory that the column name be present in the SELECT statement?
Appreciate your help in advance.

I solved it by including the date criteria in the WHERE clause of the SELECT statement and specifying the form text box names of start and end dates.
The other thing that I did was to eliminate the query name from the Docmd.openreport since the report was created from the named query.

Related

Use case statement for parameter for column name in sql where clause

I have been looking all day for a solution that works for my situation. I have found some things that are very similar but don't work for my situation, I tried them.
Here is the scenario; I have two table base and partdetails. I have an asp website (internal ONLY) that has drop down lists to select the parameters for a SQL query that fills a data grid view.
My problem is this, I need to be able, based on the drop down list boxes on the page, assign the column name that the criteria that is entered to be searched for.
Here is the query that I am trying to define: (This one returns 0 rows)
sqlCmd.CommandText = ("Select ba.referenceid, ba.partnum, pd.width, pd.length, CONVERT(varchar(12), pd.dateentered, 101) As [dateentered], ba.partqty, ba.status, ba.material From tbl_dlbase ba Join tbl_partdetails pd On ba.referenceid = pd.referenceid Where Case #field1 When 'part #' Then 'ba.partnum' When 'Spacing' Then 'pd.spacing' When 'Surface' Then 'pd.surface' When 'Height' Then 'pd.height' When 'Thickness' Then 'pd.thickness' End Like '%' + #criteria1 + '%'")
sqlCmd.Parameters.AddWithValue("#field1", ddlSc1.SelectedItem.Text)
sqlCmd.Parameters.AddWithValue("#criteria1", txbCriteria1.Text)
This is the latest version of the SQL statement that I have tried. I need to be able to set the field/column name based on the selection from the drop down list ddlsc1 on the asp page.
I have also been trying the queries in Studio manager to see if maybe I have fat fingered something but it also returns 0 rows so I know something is wrong with the query.
So how can I set the column name field using a parameter for the name. I know this is a huge security concern with SQL injection but this is an internal only site, and more importantly my boss said he wants it done with variables.
I don't really see a problem with this other than you have single quotes around your THEN values. Does this fix it?
SELECT ba.referenceid
,ba.partnum
,pd.width
,pd.length
,CONVERT(VARCHAR(12), pd.dateentered, 101) AS [dateentered]
,ba.partqty
,ba.STATUS
,ba.material
FROM tbl_dlbase ba
JOIN tbl_partdetails pd ON ba.referenceid = pd.referenceid
WHERE CASE #field1
WHEN 'part #'
THEN ba.partnum
WHEN 'Spacing'
THEN pd.spacing
WHEN 'Surface'
THEN pd.surface
WHEN 'Height'
THEN pd.height
WHEN 'Thickness'
THEN pd.thickness
END LIKE '%' + #criteria1 + '%'

How can i get my table filled automatically when i gave id from another table in ax 2009

I have a two tables in first table i filled the values with name id,
on second table if i gave the id the table needs to fill the name automatically, how can i do this please help.
You commented that the error is in the following line:
axsl.TransDate = DateTimeUtil::utcNow();
This is logic because axsl.TransDate is Date and DateTimeUtil::utcNow() return a UtcDateTime when you compile get this error Operand types are not compatible with the operator.
There are many ways to fix this error.
Try this:
axsl.TransDate = DateTimeUtil::date(DateTimeUtil::utcNow())
DateTimeUtil::date() convert UtcDateTime in Date.
or you can use today() method to return the actual date.

Searching and Replacing Null Value

I'm looking to check my SourceCode variable for Null values and then convert all Nulls to the text value BaseSource. Before I run this on live data I want to make sure that is what the following code will do:
,case ISNULL(SourceCode,' ')
when ' ' then 'BaseSource'
else SourceCode end
Can I expect that with this code Null values will first be converted to a blank spaces, and then to BaseSource within the current SourceCode column?
Thank you.
In SQL SERVER you can use a syntax like this:
UPDATE YourTable SET SourceCode = ISNULL(SourceCode, 'BaseSource')
Before UPDATE your live data you can try this SELECT:
SELECT ISNULL(SourceCode, 'BaseSource') FROM YourTable

Gridview with SQL data source is removing white spaces

I have a GridView connected to my database through an sql data source. It is bound by the follow code:
firstview = "SELECT ID, DC, DD, CYM, CB, ST FROM SCH_SCHEMANAME.TABLENAME WHERE CI = " & txtboxvalue.text & " AND ST = 'whatever' AND D = 0"
SqlDataSource1.SelectCommand = firstview
GridView1.DataBind()
There is no problem connecting to the database. Inside the database, one of the column contains extra whitespace. To make a long story short, the DD column is a short sentence that contains more than one space between some words. e.g. "This_is____a_sentence_stored___in_the_____dd_column" where each underscore is a space in this example.
When I do the databind, the spaces in between the words are all reduced to 1 space. I do, however, need to keep the exact amount of spaces between each word when the data is bound in the GridView. At the moment, it is showing in the GridView as "This_is_a_sentence_stored_in_the_dd_column" but I want to keep the amount of spaces rather than have them automatically cut down.
Can anyone help?
I was able to fix by doing the following on the RowDataBound event for the gridview.
e.Row.Cells(4).Text = e.Row.Cells(4).Text.Replace(" ", " ")
The database was retrieving the correct value, but the spaces were being parsed/encoded. JPW's links helped me with the line of code.
Thanks
It is not about a database. The browser treats multiple spaces as one. E.g. see several workarounds here: http://www.codeproject.com/Articles/30740/Avoid-Multiple-Space-Elimination-in-ASP-NET-GridVi

JasperReports: Convert Amount into Words

I am using iReport 4.7.
I want print amount in words.
For Example:
Assume Text field contains 1000 and i want print like "One Thousand".
Is anyone tell the steps to solve it?
Process your datasource before passing it to the report.
Using ibm's ICU4J you can convert amount into words by doing something like
double num = 2718;
RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(Locale.ENGLISH, RuleBasedNumberFormat.SPELLOUT);
String result = formatter.format(num);
System.out.println(result);
Will print
two thousand seven hundred eighteen
If you are using Oracle database then try this:
SELECT TO_CHAR(TO_DATE($P{ParamName}, 'J'), 'Jsp')
FROM dual
This spells out whatever number you pass through $P{ParamName}. You can use this select clause in your main query's SELECT clause and use it.

Resources