How to give NOT NULL as a parameter value in Report Builder - sql

I'm trying to build a report where i try to filter values from a table by their close dates (datetime). So far i've created a parameter called #closeDateParam and i want users to select between 2 options, one of them refers to NULL and other one refers to NOT NULL.
my sql is something like this,
select * from TABLE1 where TABLE1.CLOSED_DATE = #closeDateParam
and i've specified values for this parameter in parameter properties as
(Null) and (NOT Null)
but it seems it does not work for me.
I'd be grateful for any help since i'm a newbie at using ReportBuilder. Thanks for helping!

Related

Report Builder - 3 Parameters all in one Query. Forward dependencies are not valid

I have an issue with building my report, I have 3 params and all 3 are in a query, they are supposed to get their values from the "drop down menus" before running the reports and are used in a where cluase to get specific stuff from the database. However I can seem to get it to work.
Example Query
Select * from [Table]
Where ID = #ID and DateFrom = #DateFrom and DateTo = #DateTo
order by ID
This is the query, I tried changing the orders of the params but it doesnt work.
Error:
The report parameter 'ID' has a DefaultValue or a ValidValue that depends on the report parameter "ID". Forward dependencies are not valid.
Based on the error you reported...
"Error: The report parameter 'ID' has a DefaultValue or a ValidValue that depends on the report parameter "ID". Forward dependencies are not valid."
I suspect your ID parameter's valid values are taken from a dataset query. The dataset query uses a parameter called #ID . You cannot populate values for a parameter if the parameter you are trying to populate is required by the query.
If you are trying to get a list of available ID's to populate the ID parameter drop down then you need to create a separate dataset for this. The dataset query would be something simple like.
SELECT DISTINCT ID FROM [Table] ORDER BY ID
You can then change your ID parameter's "Available Values" dataset to point to this new dataset.
If this does not help, show you report design (the parameters at least), the parameters properties and the dataset queries for each one. Your issue should be clear once all that is visible.

Insert Image from another table based on condition

I'm new to SQL (have only been in my position for a few weeks with no prior experience) so please excuse me if this is an obvious question!
Context
I've got two tables - table 1 which contains two images (for this instance we'll call them 'Yes' and 'No' - both saved as varbinary(max)) and table 2 that contains all my other data.
I've created a new column in table 2 called Image that I want to populate with one of the images based on the value in another column ('Drivable') in table 2. The column 'Drivable' will either contain the values 'Yes', 'No' or NULL.
Question
I think I need to use a case statement but not entirely sure how to go about it.
Can anyone help?
Thanks in advance for any reply - if you need any more information then please let me know.
:)
I managed to solve the problem using the below:
SELECT
T.ClaimId
,I1.[Photo] as DriveableImage
FROM
Table1 as T
LEFT OUTER JOIN
Table2 as I1
ON
I1.ImageGroup = C.Drivable

Automatically generated SQL code throws type mismatch

My problem is that I would like to make an append query in Ms-Access 2010. I tried to realize it in query designer, but it throws an error:
Type mismatch in expression
See the generated code below:
INSERT INTO Yield ( ProcessName, Sor, Lot,
ProcessCode, Outgoing, DefectReason, DefectQty, ModifyQty )
SELECT Process.[ProcessName], Sor.[Sor], Qty.[Lot], Qty.[ProcessCode],
Qty.[Outgoing Date], Qty.[Defect Reason], Qty.[Defect Qty], Qty.[Modify_Qty]
FROM (Sor INNER JOIN ProcessCode ON Sor.[SorID] = ProcessCode.[SorID])
INNER JOIN (Process INNER JOIN Qty ON Process.[ProcessID] = Qty.[ProcessID])
ON ProcessCode.[ProcessID] = Process.[ProcessID];
The tables and the attributes are all existing. The ID numbers are indexes, the Quantities are numerical, the 'ProcessName', 'Sor', 'Lot', 'ProcessCode', 'DefectReason' attributes are strings.
What could be the problem?
Thanks in advance.
Looks ok. The best advice is divide it in smaller pieces.
http://importblogkit.com/2015/05/how-do-you-eat-an-elephant/ .
Try this:
Remove the insert part. Just try the select to make sure the join are working properly. If this fail the problem is on the join fields
Then, Put the insert again, but instead of putting table fields from the SELECT use default values. '' for strings and 0 for numeric and put the right alias for column name. That way you make sure your data is bringing the right data type. If this fail then one of the field isnt really a string or a number. Like gustav suggest probably a DATE
If that work then try to put one table field each time until you find the one causing the problem. Maybe one field doesnt support null or is receiving a bigger value than supported.
The problem was that the Yield table did not have the listed attributes. I thought that if some of the listed output attributes are not included in the output table, Access automatically creates the missing new attributes. I was wrong. The output table has to contain the attributes (rows), new attributes cannot be inserted into it this way.

Set default value for parameter in pentaho report designer

I am creating a report in pentaho report designer and need some help setting default values for a parameter that I've created.
One of the parameters labeled date fetches data from the date column of a table. While I am able to view all the dates in the drop down list, I am unable to find a way in which I can set the default value of this drop down to all (meaning all the dates together).
Is there a way in which I can set the 'all' value as default?
Assuming that you get the values for the filter from a JDBC connection in PRD, you can write a query like this. (I have used Postgresql).
This will load 'All' as the first values in the drop down and other distinct date values from your table. (Do the casting properly)
SELECT 1 AS sort,'All' AS date
UNION
SELECT DISTINCT 2 AS sort,
tablename.datecolumn::date AS date
FROM
tablename
ORDER BY sort
Then in your parameter that is shown to the user to select the date, enter All in Default Value field and select the query that we have written.
Next assuming that you use a KTR to retrieve data to your report, you can include the following query in a 'Table input' step,
(tablename.datecolumn IN (SELECT CASE WHEN('${date}' = 'All' OR '${date}' IS NULL) THEN tablename.datecolumn ELSE '${date}' END))
Hope this will help. If you have any further issues please comment below. Because this has worked perfectly for me.

How to prevent CAST errors on SSIS?

The question
Is it possible to ask SSIS to cast a value and return NULL in case the cast is not allowed instead of throwing an error ?
My environment
I'm using Visual Studio 2005 and Sql Server 2005 on Windows Server 2003.
The general context
Just in case you're curious, here is my use case. I have to store data coming from somewhere in a generic table (key/value structure with history) witch contains some sort of value that can be strings, numbers or dates. The structure is something like this :
table Values {
Id int,
Date datetime, -- for history
Key nvarchar(50) not null,
Value nvarchar(50),
DateValue datetime,
NumberValue numeric(19,9)
}
I want to put the raw value in the Value column and try to put the same value
in the DateValue column when i'm able to cast it to Datetime
in the NumberValue column when i'm able to cast it to a number
Those two typed columns would make all sort of aggregation and manipulation much easier and faster later.
That's it, now you know why i'm asking this strange question.
============
Thanks in advance for your help.
You could also try a Derived Column component and test the value of the potential date/number field or simply cast it and redirect any errors as being the NULL values for these two fields.
(1) If you just simply cast the field every time with a statement like this in the Derived Column component: (DT_DATE)[MYPOTENTIALDATE] - you can redirect the rows that fail this cast and manipulate the data from there.
OR
(2) You can do something like this in the Derived Column component: ISNULL([MYPOTENTIALDATE]) ? '2099-01-01' : (DT_DATE)[MYPOTENTIALDATE]. I generally send through '2099-01-01' when a date is NULL rather than messing with NULL (works better with Cubes, etc).
Of course (2) won't work if the [MYPOTENTIALDATE] field comes through as other things other than a DATETIME or NULL, i.e., sometimes it is a word like "hello".
Those are the options I would explore, good luck!
In dealing with this same sort of thing I found the error handling in SSIS was not specific enough. My approach has been to actually create an errors table, and query a source table where the data is stored as varchar, and log errors to the error table with something like the below. I have one of the below statements for each column, because it was important for me to know which column failed. Then after I log all errors, I do a INSERT where I select those records in SomeInfo that do not have an errors. In your case you could do more advanced things based on the ColumnName in the errors table to insert default values.
INSERT INTO SomeInfoErrors
([SomeInfoId]
,[ColumnName]
,[Message]
,FailedValue)
SELECT
SomeInfoId,
'PeriodStartDate',
'PeriodStartDate must be in the format MM/DD/YYYY',
PeriodStartDate
FROM
SomeInfo
WHERE
ISDATE(PeriodStartDate) = 0 AND [PeriodStartDate] IS NOT NULL;
Tru using a conditional split and have the records where the data is a date go along one path and the other go along a different path where they are updated to nullbefore being inserted.