REPORT -Visual Studio 2012 - sql

I am new to report.Dataset patient is a dropdownlist.Here I want to add a NULL field so thaT if i select Null it must retrieve some values from database.How can i create a NULL field in The dropdownbox of a report as below.But it is not working for me
http://msprojectnow.com/blog/reports-in-ssrs-with-multi-value-parameters-and-null-values

Assuming you are talking about a report parameter and that you intend to use Reporting Services Server to host the report. I usually find the approach below works to give provide an empty value to pick. So you add a dataset for the patient dropdown and use the query below as the data source for example.
select 0 as PatientID, ''as Patient
Union
Select PatientID, Patient
Order By Patient
Then you select Query as you source for your Patient parameter pick this data source and choose patientID as the value and Patient as the display value. If you do the same for default value but just pick Patient id, the bank value will show as your initial selection when you run the report.

Related

I have a table where I need to update or insert depending on field paramaters

I have spent many hours researching this problem and trying various solutions but I never quite find a suitable solution for my specific problem. I am new to SQL and some of the examples are confusing as well.
So here is my dilemma. I have a equipment table that tracks oil changes for specific units in a database. The table looks like this:
**id UnitID Posted_On Date_Completed Note OverDueBy**
1 BT-109F 2019-02-04 2019-02-14 Hrs Overdue 23
1 BT-108G 2020-01-17 2020-01-22 Days Overdue 12
1 BT-122K 2020-01-02 2020-01-16 Days Overdue 12
1 BT-109F 2019-02-04 Days Overdue 3
The example records above need to be created or updated by the query. The date completed is entered manually by the technician when he has completed the oil change.
What I want the query to do is, Check to see if a specific Unit has a record where the 'Date_Completed' field is empty, and if so update the 'OverDueBy' field to reflect the new value. If all the records for the specified Unit have the 'Date_Completed' fields filled in, then the query should create a new record will all fields filled in except for the 'Date_Completed' field.
Can anyone help me construct such a query?
Thanks
Clan
First create a unique partial index for the column UnitID:
CREATE UNIQUE INDEX idx_unit ON tablename(UnitID)
WHERE Date_Completed IS NULL;
so that only 1 row with Date_Completed=null is allowed for each UnitID.
So a statement like this:
INSERT INTO tablename(id, UnitID, Posted_On, Date_Completed, Note, OverDueBy)
VALUES (?, 'BT-109F', ?, null, ?, ?)
ON CONFLICT(UnitID) WHERE Date_Completed IS NULL DO UPDATE
SET OverDueBy = ?;
will insert the new values only if there is no row already for UnitID='BT-109F' with null in Date_Completed.
But if there is such a row then it will update the column OverDueBy.
I'm not sure what values you want to insert or what will be the updated value so replace the ? with the appropriate values.
Firstly I would use a view rather than a table to store any calculated data - it reduces storage overheads and will update the calculation every time the view is opened.
If you're using SQLite you should be able to get the overdue by subtracting the Posted_On from its function to return today's date something like date('now') or julianday('now') - read up on and test the functions to ensure it does what you want.
So along the lines of:-
create view MyView as select *, julianday('now') - julianday(Posted_On) as OverDueBy from ClansTable where Date_Completed is null;
If you want to store a snapshot you can always create a table from a view in any case:-
create table MyStoredOverduesOn4thFeb as select * from MyView;
You can find your units that have all Date_Completed and create a single new record like so:-
Create table CompletedUnits as select id, UnitID, max(posted_on) as latest_posted_on, '' as Date_Completed from ClansTable group by id, UnitID having count(*) = count(Date_Complete);
Test this SQL and see if you can get it working - note I've created a text field for the date. Apparently there is no date/datetime data type as such:-
https://www.sqlitetutorial.net/sqlite-date/
Hope this helps,
Phil
I think you need something like this:
MERGE INTO EQUIPMENT A
USING (SELECT * FROM EQUIPMENT B WHERE DATE_COMPLETED IS NULL) C
ON (A.UNITID=C.UNITID)
WHEN MATCHED THEN UPDATE SET A.OVERDUEBY="new value"
WHEN NOT MATCHED THEN INSERT (A.id,A.UnitID,A.Posted_On,A.Date_Completed,A.Note,A.OverDueBy)
VALUES (C.id,C.UnitID,C.Posted_On,NULL,C.Note,C.OverDueBy)
Not sure where new values from update will come from. It's not clear in your question. But something like this could work.

grafana - add new column

i use grafana with table panel, i can put 3 column (metric,value,time) but i want put 5 column (metric, metric, value, value, time)
how can i see 5 column in a table?
see below with 3 column
i need 5 column
sql in grafana panel :
that works, i use a new version of table in grafana
You can't have the same name column more than once. Change the name of the columns and it should work.
You can Do that with Grafana tooltip, identical columns name are forbidden by MySQL, nor Grafana. on your query set unique alias for each column.
on your table visualization configuration change the names as you wish.
for example:
SELECT time as time, line as value1, nb_user as value2, os_name as metric1, program as metric2 FROM Toto WHERE $__timeFilter(time) ORDER BY 1

Change tracking to show before and after value

So I enabled change tracking on the database and table and ran the below query;
SELECT *
FROM CHANGETABLE(CHANGES Cust, 0) AS CT
This returns valuable information that I can use but I am wondering if there is a way that I can show the value before and after the change?
For example - If the customer table has a name column and I change that column from 'Facebook' to 'Twitter'. That I can then see the before value (Facebook) and after value (Twitter).

SSRS - Parameter based on reference table

I have multiple datasets with the WHERE clause = #customernumber.
I have a customer number data set that contains a field with a unique id and a field that contains multiple ids.
I.e.
Customer Number | Old Customer Numbers
123 123
123 34324
123 4363
123 124214
345 345
345 436346
345 234532
678 678
I want to be able to search in the parameter box for the old customer number but use the customer number in querying my datasets.
My datasets only contain the customer number, not the old customer numbers.
While creating the parameter you can select the value and the label of the dropdown list.
In the Available Values tab select Get values from a query, for dataset just choose the dataset that query the table with new and old codes. In Value field select the new code and in the Label field select the old code.
UPDATE:
Create a parameter called OldCode. Set the data type to text or integer based on old customer code number. Don't use default or available values for this parameter.
Create a dataset that use the #OldCode parameter to return the customer number. Use something like this:
select
Customer_Number
from CustomerTable
where Old_Customer_Number = #OldCode
Create a parameter called CustomerNumber. Set Hidden property and select the data type based on the Customer_Number column. In Default Values tab select the dataset created previously and the Customer_Number column as Value field.
After that you can use #CustomerNumber in all your datasets. When user input a old code the #CustomerNumber will be populated with the related Customer_Number value.
Let me know if this helps.

choose what column to include in select based on a second select statment

i have a third party program that uses a data base table to display user created (within the app) fields on the screen so i have a table named User_Created_Fields that looks like
TABLE FIELD_NAME GROUP LABEL
products charge1 1 First Charge
products begin_date1 1 Begin Date
products end_date1 1 End Date
products charge2 2 First Charge
products begin_date2 2 Begin Date
products end_date2 2 End Date
when the app sees this in the table it displays the following in the app
Group 1
First Charge *text area for input*
Begin Date *text area for input*
End Date *text area for input*
----------
Group 2
First Charge *text area for input*
Begin Date *text area for input*
End Date *text area for input*
The app saves the data for these fields to the table and field name specified in the User_Created_Fields table so the PRODUCTS.charge1 and PRODUCTS.charge2 fields (and same for the corresponding date fields).
now i need to create a report that selects the values that are stored in the Products table but... since the fields will be added by users i need the columns selected to come from the Table and field_name columns in the User_Created_Fields table.
so the output would look like
PRODUCTS.Begin_date, PRODUCTS.End_date, PRODUCTS.Charge1, User_Created_Fields.Group
the query would look (very roughly) like
select (select Table ||'.'||field_name from User_Created_Fields where Label='First Charge' and Group= (select Group from User_created_fields where label ='First Charge') ) from Products
this is going into a crystal report so i can't just use sql to generate sql like i normally would. There may be a more crystal esq way to do this as well but i am unaware of what it is. this info is going to be combined with sales detail obviously but i left that part out for simplicitiy since this part is un-godly complicated enough. i am using crystal 11 and oracle 10
if you have read all of this you deserve a reward.... thank you.
As far as I know Crystal Reports can access stored procedures instead of sql statments. So put your code for creating the sql statement in a stored procedure and use that as the source of data for the report.
You might have to determine a maximum number of columns to support and always return that number of columns in order to make crystal happy.