CAST 0 as DateTime
How do you cast 0 as DateTime? Is this possible to do...
I am using UNION to combine two tables. I get an error when doing so...
Msg 206, Level 16, State 2, Line 1
Operand type clash: int is incompatible with date
SELECT TOP (100) PERCENT
Opportunity_Name
,Status
,Closed_Status
,Sales_Stage
,Expected_Close_Date
,Closed_Flag
,Total_Revenue
FROM
v_rpt_Opportunity
WHERE
(Expected_Close_Date >= DATEADD(MM, DATEDIFF(MM, 0, GETDATE()), 0))
UNION
SELECT TOP (100) PERCENT
0 AS Opportunity_Name
,0 AS Status
,0 AS Closed_Status
,Description AS 'Sales_Stage'
,0 AS Expected_Close_Date
,0 AS Closed_Flag
,0 AS Total_Revenue
FROM SO_Pipeline
WHERE Description NOT LIKE '%delete%'
I understand what is causing the error. In the top select statement both Closed_Status AND Expected_Close_Date are datetime values. But in the bottom statement they are int.
I understand what is causing the error. In the top select statement both Closed_Status AND Expected_Close_Date are datetime values. In the bottom statement they are int. So
I tried CASTing them as datetime, that didn’t work and I get this error.<o:p></o:p>
Conversion
failed when converting the varchar value 'Open' to data type int.
Is there a way to CAST 0 as a DateTime
Thank you,
Steve
I think the issue is not with the dates, instead it's with either Status / Closed Status i.e. one of their value is “open” and error is when that value to “int” which is not possible. Try
casting them to varchars.
SELECT TOP (100) PERCENT
Opportunity_Name
,Status
,Closed_Status
,Sales_Stage
,Expected_Close_Date
,Closed_Flag
,Total_Revenue
FROM
v_rpt_Opportunity
WHERE
(Expected_Close_Date >= DATEADD(MM, DATEDIFF(MM, 0, GETDATE()), 0))
UNION
SELECT TOP (100) PERCENT
0 AS Opportunity_Name
,CAST(0 AS VARCHAR(10)) AS Status
,CAST(0 AS VARCHAR(10)) AS Closed_Status
,Description AS 'Sales_Stage'
,0 AS Expected_Close_Date
,0 AS Closed_Flag
,0 AS Total_Revenue
FROM SO_Pipeline
WHERE Description NOT LIKE '%delete%'
Narsimha
Similar Messages
-
Cast to DATETIME Function?
Please someone correct me if I'm wrong, but it seems you can use the cast function to convert correctly formatted data to date, timestamp, etc, but it is not possible to cast to datetime?
OBIEE 11.1.1.6.2
Thanks,
GeoMy date is like '30/04/1990 15:30:00' I want to keep the time after the date... which is why I want to convert to datetime. If I convert to date then I lose the time - i.e. the output becomes 30/04/1990 00:00:00. So I thought the solution was to cast to datetime instead in OBIEE.
However, CAST("subjectarea"."table"."columnname" AS DATETIME) throws an error. Hence, I'm wondering if it is not possible to cast to datetime......
Can anyone advise?
Thanks,
George -
How to Convert MM/DD/YYYY to YYYY/MM/DD in SQL Reporting Services
i am having difficulty of converting a parameter field, called @startdate, on sql reporting services report to YYYY/MM/DD format. the parameter @Startdate was set to Data/Time. @Startdate is 6/1/2014 12:00:00 and I want to convert it
to 2014/06/01. I want to compare @Startdate with a column in database called Begindate which is in format of YYYY/MM/DD hh:mm:ss. I tried the followings
select * from Atable where cast(Atable.Begindate as date) >= cast(@Startdate as date)
select * from Atable where cast(Atable.Begindate as date >= cast(convert(datetime, @Startdate) as date)
SQL Reporting Services only gives me Text, Boolean, Date/Time, Integer and Float.
Regards,Hi Elmucho,
Sorry for the delay. I tested with the sample data you provided, however everything works well in-house. Could you please creste a new report and check the result. Here are the steps I performed:
1. Create a table and insert the following data:
Name (varchar(50)) Begindate (datetime, not null)
Lastdate (datetime, not null)
bob
2008-01-01 08:08:08.000 2010-10-10
10:10:10.000
alice
2010-10-10 10:10:10.00 2011-11-11
11:11:11.000
smith
2011-11-11 11:11:11.00 2012-12-12
12:12:12.000
2. Open SQL Server Data Tools, create the data source and add the dataset with the below query:
SELECT Name, Begindate, Lastdate
FROM [tablename ]
WHERE (CAST(Begindate AS date) >= CAST(@Startdate AS date)) AND (CAST(Lastdate AS date) <= CAST(@Enddate AS date))
3. Then, click execute button, it prompts for inputting the parameter value.
@Startdate
6/1/2008
@Enddate
5/1/2014
Enter the date and press OK.
4. Here is the result in the query designer:
Insert a table and fields. Save the report and preview:
Thanks.
Tracy Cai
TechNet Community Support -
Why doesn't SSRS like an IF Statement in my SQL Stored Procedure???
I have multiple IF Statements at the end of my SQL Stored Procedure Process that utilizes a @ReportTypeName Parameter to produce the chosen report result set
IF @ReportTypeName = 'HMO-POS New To HFHP - No Prior Year Member Spans'
BEGIN
SELECT DISTINCT
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Contract Nbr],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Subscriber Member Nbr],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Pkg],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Division Nbr],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EFF DATE],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER FIRST NAME],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER LAST NAME],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Broker Name],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ADDRESS 1],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER CITY],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER STATE],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ZIPCODE],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE1],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE2],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE3],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EMAIL],
CONVERT(VARCHAR,CAST(CONVERT(VARCHAR, [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH]) AS DATETIME),101) AS [INDV MEMBER BirthDate],
FLOOR((CAST (GETDATE() AS INTEGER) - CAST(CONVERT(DATETIME, CONVERT(CHAR(8), [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH])) AS INTEGER)) / 365.25) AS [INDV MEMBER AGE]
FROM [#TempTable_Distinct_Individual_Member_All_Info]
WHERE (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
AND [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR] NOT IN
(SELECT [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR]
FROM [#TempTable_Distinct_Individual_Member_Prior_Year_Spans])
ORDER BY [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR]
END
IF @ReportTypeName = 'HMO-POS Renewals'
BEGIN
SELECT DISTINCT
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Contract Nbr],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Subscriber Member Nbr],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Pkg],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Division Nbr],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EFF DATE],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER FIRST NAME],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER LAST NAME],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV Broker Name],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ADDRESS 1],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER CITY],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER STATE],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ZIPCODE],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE1],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE2],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE3],
[#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EMAIL],
CONVERT(VARCHAR,CAST(CONVERT(VARCHAR, [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH]) AS DATETIME),101) AS [INDV MEMBER BirthDate],
FLOOR((CAST (GETDATE() AS INTEGER) - CAST(CONVERT(DATETIME, CONVERT(CHAR(8), [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH])) AS INTEGER)) / 365.25) AS [INDV MEMBER AGE]
FROM [#TempTable_Distinct_Individual_Member_All_Info]
INNER JOIN [#TempTable_Distinct_Individual_Member_Prior_Year_Spans]
ON [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR] = [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR]
WHERE (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
ORDER BY [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR]
END
Microsoft Visual Studio and SQL Server Reporting Services did not like this! When I added my dataset and parameters accordingly, my Dataset had no fields...almost as if running the Stored Procedure in the background to get its Metadata was not working. I
know this works because I tested it as a result of a straight EXEC Command. Why doesn't Microsoft Visual Studio and SQL Server Reporting Services not like this IF? I did end up getting around this by parameterizing the WHERE clause based on the @ReportTypeName
chosen.
WHERE (@ReportTypeName = 'HMO-POS New To HFHP - No Prior Year Member Spans'
AND (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
AND [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR] NOT IN
(SELECT [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR]
FROM [#TempTable_Distinct_Individual_Member_Prior_Year_Spans]))
OR (@ReportTypeName = 'HMO-POS Renewals'
AND (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
AND [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR] IN
(SELECT [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR]
FROM [#TempTable_Distinct_Individual_Member_Prior_Year_Spans]))
I appreciate your review and am hopeful for a reply.
Thanks!Hi ITBobbyP,
I have tested on my local environment and can reproduce the issue, the issue can be caused by the temp table you are using which will also cause the data not display.
I have use below sample table and record to have a test and details information below for your reference:
Right click the DataSet to select the "DataSet Properties" and click the query designer to execute the stored procedure by click the "!" to check if you can get the data:
If you got some error, the issue can be cause by the temp table invalid, so please make sure you have add the query to create and insert recored to temp table like below:
CREATE PROCEDURE vickytest0311_1
@ReportTypeName nvarchar(50)
AS
create table #VickyTest
column1 int,
column2 varchar(20)
insert into #VickyTest values (1,'Test1')
insert into #VickyTest values (2,'Test2')
insert into #VickyTest values (3,'Test3')
IF @ReportTypeName ='Test1'
BEGIN
select * from #VickyTest
where Column1=1
END
IF @ReportTypeName ='Test2'
BEGIN
select * from #VickyTest
where Column1=2
END
GO
3. I recommend you to not use the temp table and you will not need to add the create and insert statement in the stored procedure.
4. If you still got no data, please try to click the "Refresh fields" as below:
If you still have any problem, please feel free to ask.
Regards,
Vicky Liu
Vicky Liu
TechNet Community Support -
BPC - Script - How to get the month of a date stored as an amount?
We have a account called "StartDate" in our database.
The user enter a date for this account: 01/07/2010
This date is then stored as 40360 in the db
We are trying to get the month number (7) out of this record.
We succeeded to write an sql query to do that:
Select Month( cast( as datetime ) )
From tblFact
Where = 'StartDate'
Any idea how to do that in a bpc script logic ?
Thanks,
BénédicteThere's no built-in support for any type of date math in BPC script logic.
One approach I've used is to add a property to the time dimension, ExcelTimeID. Then you can compare the value to your time periods, if your logic requires this type of condition.
*WHEN SignedData
*IS < Time.ExcelTimeID
But that doesn't solve the problem you have, where you want to know the month. I can't think of an immediate solution, other than perhaps in the original input schedule to hide a second account that submits the month number (as an integer) along with the account you have now (with the full date).
Or stick a stored proc in some logic package, scheduled to run every 10 minutes or whatever, that takes the account with the date in it, and runs your query, saving the result as the month number. Ugly in so many different ways, but it's another way to tackle the problem further upstream.
And last result is to build script logic with ridiculous hard-coding of Excel time IDs all over the place. -
Attendance Report Select Statement Help
Hello ,
i am working on the a Report for Attendance , for each employee , i want to show the report for a Date Range , i want to show
all days even if he is absent , the table structure for getting the attendance is just one Table , where i take the min time and max time for the employee
i want to show it as the below :
Date Time In Time Out
1-1 7:45 16:00
1-2 7:05 16:48
1-3 Null Null
1-4 8:00 14:00
i have created a table TCalendar with all Dates and want to join it with the Transactions Table
Select UserID ,FirstName + ' ' + LastName as [Employee Name], Convert(Varchar,min(OccurDateTime),108) as MinDate, Convert(Varchar,max(OccurDateTime),108) as maxDate
, Department , Rank , Cast(ISNull(Datediff(mi,min(OccurDateTime),max(OccurDateTime)),'') as Decimal(4,0)) / 60 as [Total Hours] , DATENAME(DW,max(OccurDateTime))+ ' ' + CONVERT(varchar, Record_Day, 106) as Date
from
TTransactionLog1 T Full Outer Join TCalendar C On C.Record_Day = T.OccurDateTime
where OccurDateTime between '2015-01-01' and '2015-01-06' and UserID <> '' and UserID = 'AKHG1030'
group by CONVERT(varchar, OccurDateTime, 106), UserID , FirstName , LastName , Department , Rank
The Results currently show like this
UserID Employee Name
MinDate maxDate
Total Hours
Date
AKHG1030 Osama Ashraf
07:44:37 12:27:07
4.716666
NULL
AKHG1030 Osama Ashraf
11:08:18 15:49:12
4.683333
NULL
AKHG1030 Osama Ashraf
07:43:00 15:31:30
7.800000
NULL
AKHG1030 Osama Ashraf
07:27:35 18:56:22
11.483333
NUL
need your HelpI think this is what you're aiming for:
DECLARE @transactions TABLE (ID INT IDENTITY, empID INT, datetime DATETIME)
INSERT INTO @transactions (empID, datetime)
VALUES (1, '2015-01-01 07:44:37'),(1, '2015-01-01 12:27:07'),(1, '2015-01-02 11:08:18'),(1, '2015-01-02 15:49:12'),(1, '2015-01-03 07:43:00'),(1, '2015-01-03 15:31:30'),(1, '2015-01-05 07:27:35'),(1, '2015-01-05 18:56:22')
DECLARE @employees TABLE (ID INT, firstName VARCHAR(30), lastName VARCHAR(30), userID VARCHAR(8))
INSERT INTO @employees (ID, firstName, lastName, userID)
VALUES (1, 'Osama', 'Ashraf', 'AKHG1030')
SELECT c.today, e.ID, MIN(datetime) AS inTime, MAX(datetime) AS outTime, DATEDIFF(MINUTE,MIN(datetime),MAX(datetime))/60.0 AS hours
FROM toolbox.dbo.calendar c
FULL JOIN @employees e
on e.id = e.id
LEFT OUTER JOIN @transactions t
ON c.today = CAST(t.datetime AS DATE)
WHERE c.today BETWEEN '2015-01-01' AND '2015-01-05'
GROUP BY c.today, e.ID
ORDER BY c.today
I created mock ups of a transactions table which holds the transactions data, and an employee ID column and an employee table which holds employee data.
I am using my calendar table/functions which you can read about here:
http://social.technet.microsoft.com/wiki/contents/articles/29260.tsql-calendar-functions-and-tables.aspx.
We full joined the employee table (creating a cartesian product between the date and all employees) so we always show every employee for every date. Then, we left outer join the transaction table to find the records for that date. We aggregate the min and
max, and use them in a date add to find the total number of hours between them. I'ved used minutes and devided by 60.0 (to force the decimal) to give partial hours.
hth. -
XL Reporter : Date critaries aren't working correctly
Hi,
yesterday I found a bug in my reports. I wanted to show all transactions between two dates : 08/01/07 and 08/14/07 but the query retrieves records it shouldn't
FACT JOU( RefDate >= @Date1 And RefDate <= @Date2 And TransTypeCode = "ARInvoice" Or TransTypeCode = "ARCreditMemo" Or TransTypeCode = "CashReceipt" ) Group By JOU.RefDate ,JOU.TransTypeCode ,FIG.OJDT_BaseRef ,FIG.OJDT_Ref1 ,FIG.OJDT_Ref2
But when I do a similar SQL query using the cast as Datetime, it works perfectly. Isn't there a way to do something like this with XL Reporter ?
select RefDate,Memo from dbo.OJDT where RefDate >= cast('05/01/2007' as Datetime) and RefDate <= cast('08/14/2007' as Datetime) and TransId in (select TransId from OJDT where Memo like 'A/R I%' or Memo like 'A/R C%' or Memo like 'Inc%')
Is anyone had the same kind of problems as me with dates ? Do you have any solutions.It seems critaries doesn't work with dimension, I changed it for a light dimension and the report works correctly. I don't understand why...
-
Hi All,
I am new to powerpivot, I have the below structure on a SQL Server database. This is basically tracking when a desktop was rebooted, rebooted user name, createddate (scheduled to run daily 3 times).
Based on the data below, how to create powerpivot report, there are few questions end user would be interested.
1. Top 10 Desktop rebooted over the time
2. Top 10 Rebooted user over the time
3. Top 10 offline Desktops
5. Pivot chart by selecting a server name - displays the latest uptime, how many times rebooted, who rebooted.
CREATE TABLE [Server].[DesktopActivity](
[Server_Name] [nvarchar](128) NOT NULL,
[Uptime] [varchar](50) NULL,
[RebootedUser] [varchar](50) NULL,
[CreatedDate] [datetime] NULL
) ON [PRIMARY]
ALTER TABLE [Server].[DesktopActivity] ADD CONSTRAINT [DF_DesktopActivity_CreatedDate] DEFAULT (getdate()) FOR [CreatedDate]
and the sample data as follows
CSR-35R5M02,9/24/2014 10:36:58 AM,NULL,2014-09-24 23:01:14.363
CSR-35J4M02,Offline,NULL,2014-09-24 23:01:41.893
CSR-34K5M02,9/24/2014 2:01:49 AM,NULL,2014-09-24 23:02:01.007
CSR-34P3M02,9/24/2014 2:01:49 AM,NULL,2014-09-24 23:02:20.117
CSR-34Q4M02,9/20/2014 11:07:01 AM,NULL,2014-09-24 23:02:39.257
CSR-35H4M02,9/24/2014 10:36:26 AM,NULL,2014-09-24 23:02:58.773
CSR-35R4M02,9/24/2014 5:11:44 PM,NULL,2014-09-24 23:03:16.230
CSR-35Z2M02,9/24/2014 8:17:00 PM,NULL,2014-09-24 23:03:39.420
CSR-3656M02,Offline,NULL,2014-09-24 23:03:59.900
CSR-3662M02,Offline,NULL,2014-09-24 23:04:20.900
CSR-3663M02,9/24/2014 10:33:01 AM,NULL,2014-09-24 23:04:28.060
CSR-36N5M02,9/24/2014 10:32:39 AM,NULL,2014-09-24 23:04:47.657
CSR-3607M02,9/24/2014 3:22:02 AM,NULL,2014-09-24 23:05:06.770
CSR-34Q1M02,Offline,NULL,2014-09-24 23:05:28.403
CSR-3626M02,9/24/2014 4:19:50 AM,NULL,2014-09-24 23:05:47.670
CSR-3642M02,9/24/2014 2:18:10 PM,NULL,2014-09-24 23:05:54.893
CSR-35C4M02,9/24/2014 5:07:41 PM,NULL,2014-09-24 23:06:04.603
CSR-36D2M02,9/24/2014 10:34:03 AM,NULL,2014-09-24 23:20:00.053
CSR-34H3M02,9/24/2014 10:34:23 AM,NULL,2014-09-24 23:20:18.190
CSR-34S6M02,9/21/2014 7:59:33 AM,NULL,2014-09-24 23:20:56.640
CSR-3615M02,9/16/2014 12:19:05 PM,NULL,2014-09-24 23:21:08.527
CSR-35D5M02,Offline,NULL,2014-09-24 23:21:25.443
CSRS-D5HKVY1,Offline,NULL,2014-09-25 07:00:40.623
CSRS-5WKKVY1,Offline,NULL,2014-09-25 07:00:49.123
CSR-34F4M02,9/24/2014 7:24:59 AM,NULL,2014-09-25 07:01:17.377
CSR-3563M02,9/25/2014 2:01:49 AM,NULL,2014-09-25 07:01:40.923
CSR-35P2M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 07:02:00.390
CSR-34Q4M02,9/25/2014 4:48:46 AM,NULL,2014-09-25 07:02:21.007
CSR-35H4M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 07:02:39.280
CSR-35R4M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 07:02:55.990
CSR-35J3M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 07:03:15.500
CSR-34H5M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 07:03:35.613
CSR-36N2M02,9/25/2014 2:01:52 AM,NULL,2014-09-25 07:03:59.180
CSR-3627M02,Offline,NULL,2014-09-25 07:04:31.133
CSR-36H1M02,9/25/2014 2:01:51 AM,NULL,2014-09-25 07:04:55.837
CSR-35G5M02,Offline,NULL,2014-09-25 07:05:19.133
CSR-3626M02,9/25/2014 4:33:55 AM,NULL,2014-09-25 07:05:36.423
CSR-34M4M02,9/25/2014 2:01:49 AM,NULL,2014-09-25 07:06:02.407
CSR-3565M02,9/24/2014 10:34:39 AM,NULL,2014-09-25 07:06:25.737
CSR-3676M02,Offline,NULL,2014-09-25 07:06:50.137
CSR-34S6M02,9/21/2014 7:59:33 AM,NULL,2014-09-25 07:07:07.180
CSR-35B4M02,9/24/2014 6:41:01 PM,NULL,2014-09-25 07:07:34.383
CSR-6K00J02,9/24/2014 4:56:26 PM,NULL,2014-09-25 07:07:58.527
CSR-34H1M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 15:07:07.943
CSR-35S1M02,9/25/2014 2:01:58 AM,NULL,2014-09-25 15:07:12.697
CSR-35D7M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 15:07:34.050
CSR-34Q2M02,Offline,NULL,2014-09-25 15:07:52.250
CSR-3686M02,Offline,NULL,2014-09-25 15:08:17.250
CSR-36C2M02,9/25/2014 10:56:55 AM,NULL,2014-09-25 15:08:39.120
CSR-36L5M02,Offline,NULL,2014-09-25 15:09:04.757
CSR-34J1M02,9/25/2014 7:12:03 AM,NULL,2014-09-25 15:09:24.123
CSR-35Y4M02,9/25/2014 2:35:30 AM,NULL,2014-09-25 15:09:44.747
CSR-3692M02,9/25/2014 2:01:50 AM,NULL,2014-09-25 15:10:03.857
CSR-34M4M02,9/25/2014 2:01:49 AM,NULL,2014-09-25 15:33:38.300
CSR-3542M02,9/25/2014 6:17:04 AM,NULL,2014-09-25 15:33:57.437
CSR-35R6M02,6/10/2014 9:05:08 AM,NULL,2014-09-25 15:34:31.080
CSR-3615M02,9/16/2014 12:19:05 PM,NULL,2014-09-25 15:34:57.917
CSR-35P4M02,9/25/2014 7:55:17 AM,NULL,2014-09-25 15:35:19.560
CSR-34S1M02,9/25/2014 2:01:48 AM,NULL,2014-09-25 23:05:13.580
CSR-3632M02,9/25/2014 4:41:10 AM,NULL,2014-09-25 23:05:34.410
CSR-35C4M02,9/25/2014 2:01:49 AM,NULL,2014-09-25 23:05:56.323
CSR-34Q7M02,Offline,NULL,2014-09-25 23:15:30.360
CSR-3542M02,9/25/2014 6:17:04 AM,NULL,2014-09-25 23:15:39.897
CSR-36H7M02,9/25/2014 9:31:06 AM,NULL,2014-09-25 23:16:06.240
CSR-35N5M02,9/25/2014 4:01:27 PM,NULL,2014-09-25 23:16:16.977
CSR-34N4M02,8/4/2014 8:00:58 AM,NULL,2014-09-25 23:16:38.230
CSR-3503M02,9/4/2014 3:03:16 PM,NULL,2014-09-25 23:16:47.820
CSR-35D5M02,Offline,NULL,2014-09-25 23:16:59.857
CSR-36F2M02,Offline,NULL,2014-09-25 23:17:13.857
CSR-6K10J02,9/25/2014 11:41:49 AM,NULL,2014-09-25 23:17:28.983
CSR-BCFQBZ1,9/26/2014 6:47:54 AM,NULL,2014-09-26 07:00:09.470
CSRS-3HYKVY1,Offline,NULL,2014-09-26 07:00:13.443
CSR-6K0YH02,9/26/2014 2:01:52 AM,NULL,2014-09-26 07:00:40.293
CSR-34R3M02,9/26/2014 2:01:54 AM,NULL,2014-09-26 07:00:50.220
CSR-34J5M02,Offline,NULL,2014-09-26 07:01:09.430
CSR-35J4M02,9/26/2014 2:01:49 AM,NULL,2014-09-26 07:01:19.130
CSR-34W3M02,9/26/2014 2:01:50 AM,NULL,2014-09-26 07:01:33.583
CSR-34K5M02,9/26/2014 2:01:49 AM,NULL,2014-09-26 07:01:38.330
CSR-34P3M02,9/26/2014 2:01:49 AM,NULL,2014-09-26 07:01:58.957
CSR-35C2M02,9/26/2014 2:01:47 AM,NULL,2014-09-26 07:02:13.427
CSR-34K3M02,Offline,NULL,2014-09-26 07:02:19.430
CSR-34H1M02,9/26/2014 2:01:52 AM,NULL,2014-09-26 07:02:39.360
CSR-35R4M02,9/26/2014 2:01:48 AM,NULL,2014-09-26 07:02:53.797
CSR-35P6M02,9/26/2014 2:01:49 AM,NULL,2014-09-26 07:02:56.250
CSR-35S4M02,9/26/2014 2:02:13 AM,NULL,2014-09-26 07:03:09.637
CSR-35Z2M02,9/26/2014 2:01:50 AM,NULL,2014-09-26 07:03:16.773
CSR-35H1M02,9/26/2014 2:01:50 AM,NULL,2014-09-26 07:03:19.150
CSR-35T4M02,9/25/2014 1:33:10 PM,NULL,2014-09-26 07:03:21.520
CSR-35M4M02,9/26/2014 2:01:50 AM,NULL,2014-09-26 07:03:27.900
CSR-34H5M02,9/26/2014 2:01:48 AM,NULL,2014-09-26 07:03:33.883
CSR-35H5M02,9/26/2014 2:01:48 AM,NULL,2014-09-26 07:03:36.360
CSR-3656M02,Offline,NULL,2014-09-26 07:03:39.930
CSR-34R7M02,Offline,NULL,2014-09-26 07:03:43.930
CSR-3653M02,9/25/2014 9:21:02 AM,NULL,2014-09-26 07:03:46.380
CSR-3652M02FORD,Offline,NULL,2014-09-26 07:03:52.587
CSR-36N2M02,9/26/2014 2:01:51 AM,NULL,2014-09-26 07:03:57.433
CSR-3663M02,9/26/2014 2:01:49 AM,NULL,2014-09-26 07:04:09.870
CSR-36C2M02,9/26/2014 2:01:50 AM,NULL,2014-09-26 07:04:14.740
CSR-36H2M02,Offline,NULL,2014-09-26 07:04:18.433
CSR-35W6M02,Offline,NULL,2014-09-26 07:04:22.433
GaneshHi Greg,
I really appreciate your time to discuss it. Here are my answers.
Server name - unique key for servers.
Nope, since I run it 3 times a day it will have 3 entries for each of the server.
Uptime - I'd expect this to be a length of time since last reboot, but this is clearly not the case.
It is datetime which is basically the last reboot time
Is this the time of the last reboot? Yes
Does offline mean it's offline at the time the row was loaded, or has been offline? Yes
How long has it been offline? There is a specific set most of the time it is offline
RebootedUser - these are all null so you cannot have top rebooteduser. Is this an error or am I missing
something? If it is NULL, the computer is offline.
CreatedDate - Is this the insert time into the table? Yes
These are all strictly greater than the dates in Uptime (I had to create a new field and remove the
'Offline' entries and cast to datetime) I don't see this field would have a Offline value.
Why do you have datetimes in a text field (Uptime)?. Because it will have either a datetime, Offline, Access
Denied.
How do I know how many time a server has been rebooted?
From the table data, for a given period of time, if I get the distinct Uptime for each server
is the no. of times it got rebooted.
Since RebootedUser is strictly null, how do I identify top rebooted users?
It is strictly NULL only for offline computer.
Let me give clean data and we will go from there.
Thanks again for your time.
Ganesh -
How to calculate the difference between values in a custom PSObject?
If I have a PSObject (created from an imported CSV) that has data like the following:
date,Total size of files uploaded
03-17-2014 09:08,1293334574547
03-17-2014 09:10,1293335326912
03-17-2014 09:13,1293336523562
03-17-2014 09:14,1293337541156
03-17-2014 09:16,1321031223511
03-17-2014 09:16,1321032156844
This CSV will have lines added to it, so the total number of lines will vary.
Is there a way that two most recently added values and calculate the difference of the "Total size of files uploaded" values?
I have the columns properly cast as datetime and
int64 already using this:
$csv = Import-Csv $csvLocation |
Where-Object { ![string]::IsNullOrWhiteSpace($_.datetime) } |
Foreach-Object {
$_.datetime = $_.datetime -as [datetime]
$_."Total size of files uploaded" = $_."Total size of files uploaded" -as [int64]
$_ }
I tried searching thinking surely there must be someone else who has tried to do this" but I cannot find anything. I am just not sure how to approach this problem. Any help would be appreciated!Assuming all of your records are sequential with the last two being the most recent you could use this:
$csv = Import-Csv $csvLocation |
Where-Object { ![string]::IsNullOrWhiteSpace($_.datetime) } | select -last 2
Foreach-Object {
$_.datetime = $_.datetime -as [datetime]
$_."Total size of files uploaded" = $_."Total size of files uploaded" -as [int64]
$_ }
$Difference = $csv[1]."Total size of files uploaded" - $csv[0]."Total size of files uploaded"
This uses the index of the imported array and just the last two records. Note that this will give a negative value if the total is less in the later record. Hope this helps!
You could also use
| sort datetime -ascending | select -last 2
if they aren't already in order... -
Constructing a View into time dependant data
1. I have a table with data like this:
PersonID
DateTime
Temperature
Pressure
2. I want to build a view into this table so that it shows up as follows:
PersonID DateTime1 DateTime2 DateTime3 .....
1 Pressure1 Pressure2 Pressure3 ......
1 Temperature1 Temperature2 Tempearture3 .....
2 :
how would I do this?Below query will work above SQL 2005,
--create table routineCheck(PersonID int, [datetime] datetime, Temperature int, Pressure int)
--insert into routineCheck values
--(1,'01/01/2014', 61, 55),
--(2,'02/01/2014', 60, 52),
--(1,'01/05/2014', 62, 53),
--(3,'01/08/2014', 60, 55),
--(1,'02/07/2014', 63, 54),
--(2,'01/12/2014', 63, 55)
declare @cols nvarchar(max)
declare @stmt nvarchar(max)
select @cols = isnull(@cols + ', ', '') + '[' + cast(T.[datetime] as varchar)+ ']' from (select distinct [datetime] from routineCheck) as T
print @cols
select @stmt = '
select *
from (select PersonID, [datetime], Temperature from routineCheck) as T
pivot
max(T.temperature)
for T.[datetime] in (' + @cols + ')
) as P '
select @stmt = @stmt + ' union all
select *
from (select PersonID, [datetime], Pressure from routineCheck) as T
pivot
max(T.pressure)
for T.[datetime] in (' + @cols + ')
) as P1 order by PersonID'
exec sp_executesql @stmt = @stmt
Regards, RSingh -
Error when using cast and convert to datetime
I run a stored procedure
usp_ABC
as
begin
delete from #temp1
where #temp1.ResID not in
( select Col1
from TableA
where ( @I_vId = -1 or Doc_Field_ID = @I_vId)
and ColA1 = 2 and FieldValue !=''
and cast ( FieldValue as DATETIME ) = cast (@strvalue_index as DATETIME)
and ResID = #temp1.ResID
and TypesId = @I_vTypeId
end
But return message "Conversion failed when converting date and/or time from character string.'
Format of Column FieldValue is nvarchar(400)
@strvalue_index = '05/05/2013'
So I see in article http://technet.microsoft.com/en-us/library/ms174450.aspx MS say about MS SQL Server and SQL Server Compact.
Then I re-write proc:
delete from #temp1
where #temp1.ResID not in
( select Col1
from TableA
where ( @I_vId = -1 or Doc_Field_ID = @I_vId)
and ColA1 = 2 and FieldValue !=''
and cast ( cast(FieldValue as nvarchar(200)) as DATETIME ) = cast (@strvalue_index as DATETIME)
and ResID = #temp1.ResID
and TypesId = @I_vTypeId
so stored run success.
I don't understand how?
When i run only statement in MS SQL Studio Management, the statement run success.
Thanks all,No bad dates in my data.
Apparently you have. Or, as Johnny Bell pointed out, there is a clash with date formats. Did you try the query with isdate()?
For SQL 2008, you need
CASE WHEN isdate(FieldValue) = 1
THEN CAST (FieldValue AS datetime)
END =
CASE WHEN isdate(@strvalue_index) = 1
THEN CAST (@strvalue_index AS datetime)
END
Erland Sommarskog, SQL Server MVP, [email protected]
I think date formats is OK. So when I re-write stored:
and cast ( FieldValue as DATETIME ) = cast (@strvalue_index as DATETIME)
=>
and cast ( cast(FieldValue as varchar(200)) as DATETIME ) = cast (@strvalue_index as DATETIME)
the stored procedure will run success. I see in http://technet.microsoft.com/en-us/library/ms174450.aspx MS
has an IMPORTANT:
Important
When using CAST or CONVERT for nchar, nvarchar, binary, and varbinary,
SQL Server truncates values to maximum of 30 characters. SQL Server Compact allows 4000 for nchar and nvarchar, and 8000 for binary and varbinary. Due
to this, results generated by querying SQL Server and SQL Server Compact are different. In cases where the size of the data types is specified such as nchar(200), nvarchar(200), binary(400), varbinary(400), the results are consistent across SQL Server and
SQL Server Compact.
I can't explain it in this case -
I have installed SQL Server Express 2008 R2 on a Windows 7, language Brazilian-Portuguese ( PT-BR ). When I run a function which converts string to datetime it is raising conversion exception. I have tried the ANSI format 'yyyy-mm-dd' and 'mm-dd-yyyy', but
the only one that works is 'dd-mm-yyyy'. Is there any kind of settup that should be made to reset SQL Server to the ANSI default ?
Jayme JeffmanDatetime/string conversion:
http://www.sqlusa.com/bestpractices/datetimeconversion/
Starting with SQL Server 2012, TRY_CONVERT() is available for date validity check:
http://beyondrelational.com/modules/2/blogs/70/posts/19841/data-validation-using-tryconvert-function.aspx
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
I am running into a strange issue which is preventing me to finish my project. Any help would be greatly appreciated.
It looks like the CONVERT (the same goes for CAST) function treats DATE and DATETIME conversions differently when executed by a user with the Dutch language settings.
Here is what I mean, I run the following query:
SELECT CONVERT(DATE, '2014-09-01 23:00:00'), CONVERT(DATETIME, '2014-09-01 23:00:00')
The results are:
2014-09-01, 2014-01-09 23:00:00
The conversion to DATETIME swapped the month and the day around, while this doesn't happen for the DATE conversion. The DATE conversion is the correct format, since I supplied it YYYY-MM-DD HH:mm:ss.
When I run the same query using a user with the default language settings (en-US I assume) the same query works fine (no swapping of month and day values).
Can someone explain why this is happening? And maybe more important how to prevent it or workaround it (changing the language for the user from Dutch to default is not an option)?
>> Can someone explain why this is happening? And maybe more important how to prevent it or workaround it (changing the language for the user from Dutch to default is not an option)? <<
CONVERT() is an old Sybase string function. It was created to keep 960's COBOL programmers happy since SQL does not have a PICTURE clause to put data in display formats.
CAST() is the ANSI/ISO Standard function to convert data types and this is what you should be using. It is not a string function. It uses the ISO-8601 standard for dates (yyyy-mm-dd), as you have seen. This is the only -– repeat, only! -- format allowed in
SQL. Microsoft is a few decades behind and trying to catch up now.
A good SQL programmer will do any local display formatting in the presentation, which will handle local languages that are never used in the database. Want to have some fun? The names of months in Polish, Czech, Croatian, Ukrainian and Belarusian not based
on the Latin names used in most European languages.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
I am trying to compare a DB2 date format to a date variable from SSIS. I have tried to set the variable as datetime and string. I have also casted the SQL date as date in the data flow task. I have tried a number of combinations of date formats, but no luck
yet. Does anyone have any insights on how to set a date (without the time) variable and be able to use it in the data flow task SQL? It has to be an easy way to accomplish that. I get the following error below:
An invalid datetime format was detected; that is, an invalid string representation or value was specified. SQLSTATE=22007".
Thanks!Hi Marcel,
Based on my research, in DB2, we use the following function to convert a string value to a date value:
Date(To_Date(‘String’, ‘DD/MM/YYYY’))
So, you can set the variable type to String in the package, and try the following query:
ACCOUNT_DATE BETWEEN '11/30/2013' AND Date(To_Date(?, ‘DD/MM/YYYY’))
References:
http://stackoverflow.com/questions/4852139/converting-a-string-to-a-date-in-db2
http://www.dbforums.com/db2/1678158-how-convert-string-time.html
Regards,
Mike Yin
TechNet Community Support -
In OBIEE rpd convert varchar to datetime
Hello,
Can anyone help one how can we convert a column that is set to varchar to datetime in obiee;
Suppose COLUMN_A is varchar and keeps value like '2008-12-30 10:11:22'
and we want to convert it DATETIME.
Thanks and Regardsuse cast(column as TIMESTAMP)
Maybe you are looking for
-
Hi ive had my macbook pro for a week or so and when i open after its been in sleep mode for quite a while it will usually make that ejecting noise. It doesnt make the ejecting noise evreytime i open it just sometimes. Is this normal HELP
-
User Exit in VA02 - Fast Change of selection
Hello Experts, Is there an existing user exit in VA02 that can be used to add another menu item under menu Edit > Fast Change of ... I would like to add another item under that I can use to change the user status of the item. Thanks in advance. Regar
-
Hi, I am working on an a alv report.In the selection screen,if the fiscal period is input based on that the dates have to be calculated and have to be displayed as column headers in the o/p.This colum is dynamic and will change based on the values gi
-
I used expdp to create a no rows export (content=metadata_only) of a 10.2.0.4 database. I am now trying to import the structures into a newly create 11.2.0.3 database using impdp. Here is the command used to run the import. impdp system/password DIRE
-
How toTransfer photos from Photoshop Starter 3.2 edition to Photoshop Family
I have been using Photoshop Album Starter trial Edition 3.2 for a few years, then recently I have been getting an Adobe registering form pop up which i completed so I could unlock and access my photos. An email was sent only to say that the version P