I am comparing a datetime field on two rows of a table - sql-server

I have a table that has several rows of data for a single ID. I need to compare a datetime field from a row where a column is = "a" AND grab the datetime and compare it to the same column where the second row is = "b". IF the time is different I want to report both of these times.
The report is working with the dates but not with the time.
IE if the dates are the same don't grab the data but of the minutes are different grab the data.
I have created time column but it is not one the table so it is not working. I am guessing that I need to extract the time from the datetime field as well.
Any thoughts or ideas?

Related

In MS Access how do you filter out the values in a column and add each in a new column?

I think the best way i can explain this is with a example: I have a table with Date, Location and Count as fields. For each day is a record of counts for each location. I want to reformat it with a query to filter each column by the location.
In MS Access in design view, I added the Date column and the Count column. I set the criteria of the count column to [Count]="LA". That gave me the counts for the LA column. But when I added a second count column and set the criteria to [Count]="CH", the results came back with nothing. Nothing shows up for LA and CH. Newbie here but how can i accomplish this? I'd like to do this in reports as well once this query is successful. Thanks.

SSIS/visual studio- using derived column transform to count distinct values and sort by two variables?

I have three columns of data- incident_ID, date, state.
The incident_ID are each unique, date is in year format only and ranges from 2013 to 2016, states are in no particular order and repeat if an incident occurs w/in the same state in the same year.
I'm going to be combining this data w/ another table, but first I need to organize the data to better match the other table's format- which is laid out showing the year, state, and dollars spent per state. So for 2013, I would have 51 rows (each state + DC) and each state would have a dollar amount- then rinse/repeat down the table through to 2016.
I'm pretty new to SSIS/Visual Studio, but from my understanding I should be able to use a Derived Column Transform to accomplish this.... but I don't know how to get there.
Is there a way to use Derived Column to 'count' and rearrange the data in order to show how many incidents occurred per state in the given year?
There is no aggregate (like SUM,Count,Min,Max) functionality in Derive Columnenter code here.For count, you can use ROW COUNT Task or you can insert the data into SQL table and then you can call the result value in derived column.

Repeat non-pivot column in SSRS

Referring to the image, I would like to repeat the salesagent column after every few rows. How do I do this in SSRS?
Note: My report will have a start and end date parameter for customers to choose. I will be using the date column for pivoting purposes. If a customer chooses to run the report for six months, they will have plenty of date columns so they are requesting to repeat the non-pivoted header column every seven days/column. Is it possible?
Let me know if more information is needed from me.

How to check the data in sql server if it is there for everyminute

I have table with
fields: Id, ChId, ChValue, ChLoggingDate
Now the data will be saved for everyminute in to the database. I need a query to check if the data exists for every minute in the table through out the year for a particular weekday. That is, all Monday's in 2013 if it has complete data for that day calculate the arithmetic mean for the year of Monday's.
YOu will need a table - or a table value function - to create a timestamp for every minute, then you can join with that and check where the original table has no data.
Only way - any query otherwise can only work with the data it has.
This is a common approach for any reporting.
http://www.kodyaz.com/t-sql/create-date-time-intervals-table-in-sql-server.aspx
explains how, you just must expand it to a times table. If you separate date and time you can get away with a time table (00:00:00 to 24:59:59) and a date table separately.

Dealing with repeated fields

I'm storing a log on the server with multiple lists where I store some data such as dates and information associated to these dates. The first field of the first list corresponds to the first field of the rest, the second field of the first list to the second field, and so on.
Using the FLATTEN function I managed to show this information, but it shows a combination of the whole data on the lists. Having 4 lists 3 fields each, generates 12 different rows.
Is there any way to show only three results, by order on the lists?
I don't love this solution, but it's the first idea that comes to mind that solves your problem:
SELECT dates, lead, userID FROM
(SELECT NTH(1, dates) WITHIN RECORD dates, NTH(1, lead) WITHIN RECORD lead, userID
FROM [egolike.com:egolike-production:egotest.egoViews]),
(SELECT NTH(2, dates) WITHIN RECORD dates, NTH(2, lead) WITHIN RECORD lead, userID
FROM [egolike.com:egolike-production:egotest.egoViews]),
(SELECT NTH(3, dates) WITHIN RECORD dates, NTH(3, lead) WITHIN RECORD lead, userID
FROM [egolike.com:egolike-production:egotest.egoViews])
WHERE dates IS NOT NULL
Basically we are mapping the Nth value of a column within a record to the Nth value of the other column. A drawback is the need of explicitly calling each Nth place by number. Hopefully you can re-import the data with a different structure! (One repeated column, containing the aligned records)

Resources