Insert Date and Time columns in SSRB - sql

I am attempting to generate a report that will have data automatically inserted into it from a server. Normally, I insert a variable from fields in the data set and run the report. However, the task I have been given is to insert date/time columns with every value column and report builder doesn't seem to like that. It inserts a single date/time column on the far left and then all the values. If I try to put a date/time column in between values, it pushes that column to the far right/last column.
It should go
datetime,value1,
datetime,value2...
and so on.
At present it goes like
datetime,value1,value2...datetime.
Is this achievable?
And if so, how can I do this?

Related

Create table without omitting empty rows?

I have a short question but no reproducible sample as I simply use the standard function for now.
I want to use SQL's CREATE TABLE function. However, I want the table to display rows even if there are no data points for that specific ovbservation. Currently, whenever there is no data for a certain row, the whole row gets omitted. Ideally I'd like it to still display the row for that specific date, and just have empty cells wher ethe data is missing.
This is important because I need the table to be of specific size, even if data is missing.
One idea I had was to include a WHERE ROWNUM statement, which refers to a materialised view or table of exactly the size I want the table to be in. Is this possible? Any other solution is welcome.
Create table first of all.
use insert statement to insert all the required rows at once (empty rows with only date, or rowindex)
'View' idea is not better, because you have to show those record (empty rows to enter data perhaps) to user, so if user enters data in 5th rows, you will not be able to add 5th row in table prior to first 4 rows.

Derived date calculation

I am currently entering data into a SQL Server database using SSIS. The plan is for it to do this each week but the day that it happens may differ depending on when the data will be pushed through.
I use SSIS to grab data from an Excel worksheet and enter each row into the database (about 150 rows per week). The only common denominator is the date between all the rows. I want to add a date to each of the rows on the day that it gets pushed through. Because the push date may differ I can't use the current date I want to use a week from the previous date entered for that row.
But because there are about 150 rows I don't know how to achieve this. It would be nice if I could set this up in SQL Server where every time a new set of rows are entered it adds 7 days from the previous set of rows. But I would also be happy to do this in SSIS.
Does anyone have any clue how to achieve this? Alternatively, I don't mind doing this in C# either.
Here's one way to do what you want:
Create a column for tracking the data entry date in your target table.
Add an Execute SQL Task before the Data Flow Task. This task will retrieve the latest data entry date + 7 days. The query should be something like:
select dateadd(day,7,max(trackdate)) from targettable
Assign the SQL result to a package variable.
Add a Derived Column Transformation between your Source and Destination components in the Data Flow Task. Create a dummy column to hold the tracking date and assign the variable to it.
When you map the Excel to table in a Data Flow task, map the dummy column created earlier to the tracking date column. Now when you write the data to DB, your tracking column will have the desired date.
Derived Column Transformation

MS Access Delete query based on combobox

I have a table with a bunch of different fields. One is named period.
The period is not part of the raw data but I run a query when I import new data to the database that gives each record a period.
Now I need a delete query that will delete all the records that have the same period as what is selected in a combobox.
The values in the combobox come from a calendar table that contain all the possible values that could be in that period column at any time.
This is the basic query i thought would solve this issue but it tells me it is going to delete 0 rows every time I run it:
DELETE *
FROM PlanTemp
WHERE PlanTemp.period = Forms![Plan Form]!Combo163;
If you don't need the key field, just remove it.
Look at the "PROPERTIES" section and look at the column names.
Ether remove it there, or from your QUERY source.
You can also look at the Data section of the properties, and change your BOUND column, to Column 2... or whatever holds the data you want to use.

stored procedure sql (Excel data to T-SQL)

I need to set up a new company for automated data import. The utility has provided the data in a spreadsheet. (Image 1)
Based on this data, I need to create a stored procedure that will identify the correct meter, if it exists, and perform either an insert or update to the monthly data table. For automated utility data import, I want to make sure I restrict everything to a particular utility company.
The steps are the following ( I am having a hard time converting this to SQL)
1- I just want a script that identify the correct meter to see if it exists, basically check the Meter# column in the excel with the MeterNumber column in the Meters table.
2- The next step is perform either an insert or update to the MonthlyData table. This is a screen shot of all its columns.
3- Then I just want to make sure that I am restricting everything to the particular company which in this case Site1 since 2 different companies might have the same meter#. The UtilityCompany table contains 3 columns: ID, Name, UtilityType
I honestly do not know from where to get started, would anybody help me with the script? Thank you
You will want to:
perform a Bulk Insert operation to take your data from the excel file into a staging table.
write a query to select ALL rows for the corresponding utility company (notice I didn't see iterate over each row...). This select could be an update where you update an additional column to mark the row as an INSERT, or an UPDATE.
Then the last step (2 parts), retrieve all of the rows that were marked as INSERT, and insert those into your table. Then grab all rows that were marked with an UPDATE, and update their corresponding values based on your matching criteria.

Date in a short text data type field... Select query trouble

In my Access database, I have a table called customers. In this table I have a column called DateEntered. The data type for the field is short text.
The values in this column are not coherent - they come in several variations:
MM-DD-YYYY,
MMDDYYYY and
MM/DD/YYYY.
There doesn't seem to be any standard set.
My goal is to select all customers from 2012. I tried
select *
from customers
where DateEntered <('%2013') AND >('%2012');
but it comes up blank when I run it.
Can anyone point out what I'm failing to do correctly & more importantly explain why exactly this query doesn't work in Access? From my understanding of SQL (not very advanced) this should work.
Another variant)
select * from customers where RIGHT(DateEntered, 4) = '2012'
If you have control over the database and application code, the best way to handle this is to use an actual Date field instead of text in the table.
One way to handle this would be to add a new field to the table, write a query or two to correctly convert the text values to actual date values, and populate the new field.
At this point, you would then need to hunt down the application code the refers to this field in any way and adjust to treat the field as a date, not text. This includes your insert and update statements, report code, etc.
Finally, as a last step, I would rename the original text field (or remove it altogether) and rename the new date field to the original field name.
Once you fix the problem, querying against the field will be a piece of cake.
Alternatively, if you can't alter the table and source code, you can use the date conversion function CDATE() to convert the text value to an actual date. Note that you may need to guard against non-date entries (NULL or empty string values, as well as other text values that aren't really dates in the first place). The IsDate() function can be your friend here.
If you have the time and patience, fixing the data and code is the better approach to take, but sometimes this isn't always feasible.
Why don't you use LIKE operators (they're appropriate when you have a pattern using % and _):
select * from customers where DateEntered like '%2013' or DateEntered like '%2012'