Showing posts with label solve. Show all posts
Showing posts with label solve. Show all posts

Thursday, March 29, 2012

Date range + parallel time

Hi,

I'm quite new to MDX and found a problem I can not solve. I have a fact table which contains a start date and an end date, plus several measures. I also have a time dimension, with years and months. I need to dynamically build an mdx query that, given a year and a month, would show any measure in the fact table whose start date is lower than the given date and the end date is higher than the given date. To complicate things a bit, the same query must show the same measure in the previous year to the given date. Both results must be in the same axis.

We know how to show each result separately, using date ranges in the WHERE clause, but have no idea about how to combine both results.

Thanks

--eduardj

Finally solved it.

I created a date range dimension, with all the date ranges in the original fact table, and a measure-less fact table with a relationship with the new date range dimension and the old time dimension. After that, I created a Many-to-Many relationship between the original fact table and the time dimension through the newly created fact table. Besides, I created a hierarchy in the time dimension which related the times (parallel) that always had to be shown together.

Kind of messy, but it works beautifully.

thanks

--eduardj

Wednesday, March 7, 2012

Date format change in the server

Hi,
Can anyone help me to solve this query regarding Date format in SQL Server
Is it possible to change the Date format in the SQL Database server. Is
this dependent upon the system date settings in the Control Panel.
Regards,
VB Babunath
Hi
SQL Server stores the data an a number and does not care about the setting
at OS level. Date format display is determined by the client and has
nothing to do with the server.
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"VBB" <VBB@.discussions.microsoft.com> wrote in message
news:A2D2D692-6699-4EF2-B0E7-C75B9E1609D5@.microsoft.com...
> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath
|||See "set dateformat" in BOL, but better use ISO format (see convert function,
styles 112 and 126), because sql server will always interpret the values as
datetime, independently of the language and "set dateformat" setting.
Example:
set dateformat mdy
go
select cast('20050922' as datetime)
go
-- error
select cast('22/09/2005' as datetime)
go
set dateformat dmy
go
select cast('20050922' as datetime)
go
-- error
select cast('09/22/2005' as datetime)
go
AMB
"VBB" wrote:

> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath
|||The question is very broad. I suggest you start by reading
http://www.karaszi.com/SQLServer/info_datetime.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"VBB" <VBB@.discussions.microsoft.com> wrote in message
news:A2D2D692-6699-4EF2-B0E7-C75B9E1609D5@.microsoft.com...
> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath

Date format change in the server

Hi,
Can anyone help me to solve this query regarding Date format in SQL Server
Is it possible to change the Date format in the SQL Database server. Is
this dependent upon the system date settings in the Control Panel.
Regards,
VB BabunathHi
SQL Server stores the data an a number and does not care about the setting
at OS level. Date format display is determined by the client and has
nothing to do with the server.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"VBB" <VBB@.discussions.microsoft.com> wrote in message
news:A2D2D692-6699-4EF2-B0E7-C75B9E1609D5@.microsoft.com...
> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath|||See "set dateformat" in BOL, but better use ISO format (see convert function,
styles 112 and 126), because sql server will always interpret the values as
datetime, independently of the language and "set dateformat" setting.
Example:
set dateformat mdy
go
select cast('20050922' as datetime)
go
-- error
select cast('22/09/2005' as datetime)
go
set dateformat dmy
go
select cast('20050922' as datetime)
go
-- error
select cast('09/22/2005' as datetime)
go
AMB
"VBB" wrote:
> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath|||The question is very broad. I suggest you start by reading
http://www.karaszi.com/SQLServer/info_datetime.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"VBB" <VBB@.discussions.microsoft.com> wrote in message
news:A2D2D692-6699-4EF2-B0E7-C75B9E1609D5@.microsoft.com...
> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath

Date format change in the server

Hi,
Can anyone help me to solve this query regarding Date format in SQL Server
Is it possible to change the Date format in the SQL Database server. Is
this dependent upon the system date settings in the Control Panel.
Regards,
VB BabunathHi
SQL Server stores the data an a number and does not care about the setting
at OS level. Date format display is determined by the client and has
nothing to do with the server.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"VBB" <VBB@.discussions.microsoft.com> wrote in message
news:A2D2D692-6699-4EF2-B0E7-C75B9E1609D5@.microsoft.com...
> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath|||See "set dateformat" in BOL, but better use ISO format (see convert function
,
styles 112 and 126), because sql server will always interpret the values as
datetime, independently of the language and "set dateformat" setting.
Example:
set dateformat mdy
go
select cast('20050922' as datetime)
go
-- error
select cast('22/09/2005' as datetime)
go
set dateformat dmy
go
select cast('20050922' as datetime)
go
-- error
select cast('09/22/2005' as datetime)
go
AMB
"VBB" wrote:

> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath|||The question is very broad. I suggest you start by reading
http://www.karaszi.com/SQLServer/info_datetime.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"VBB" <VBB@.discussions.microsoft.com> wrote in message
news:A2D2D692-6699-4EF2-B0E7-C75B9E1609D5@.microsoft.com...
> Hi,
> Can anyone help me to solve this query regarding Date format in SQL Server
> Is it possible to change the Date format in the SQL Database server. Is
> this dependent upon the system date settings in the Control Panel.
> Regards,
> VB Babunath

Sunday, February 19, 2012

Date conversions and arithmetic

Hi folks,
New to SQL programming and reading about CONVERT, CAST and the DATE
functions aren't giving me enough info. to solve my problem.
My data looks like this:
20050416000000 Admitted 33
20050416000000 Discharged 26
20050416000000 Registered 70
20050417000000 Admitted 33
20050417000000 Discharged 21
20050417000000 Registered 65
Column I'm interested in Discussing is the first, which is stored in its
table as a VARCHAR(25) and is called DateID. So, clearly it's not a DATETIM
E
or SMALLDATETIME.
The first 8 characters represent the yyyymmdd but it's just a string. The
trailing zeros stored seem to be junk.
I need todo the SELECT to get that column from today and only the previous
seven days. Also, I want it formatted in mm/dd/yyyy in my output if
possible.
This is the closest I've gotten:
Select DateID
from DispositionCount
WHERE ((SUBSTRING(DateID,1,4) = DATEPART(year,GETDATE())) and (SUBSTRING
(DateID,5,2) = DATEPART(month,GETDATE()))) and (DATEDIFF(day, SUBSTRING
(DateID,7,2), DATEPART(day,GETDATE()))<= 7)
Can anyone tell me how to do this? Getting the DBA to change the column to a
proper datetime is not feasible.
Thanks,
hbcpTry This...
Select ... Convert(VarChar(10), Cast(Left(DateID, 8) As DateTime), 101)
DateName
From ...
Where Left(DateID, 8) Between DateAdd(day, -7, getdate() And getdate()
"hbcp_1" wrote:

> Hi folks,
> New to SQL programming and reading about CONVERT, CAST and the DATE
> functions aren't giving me enough info. to solve my problem.
> My data looks like this:
> 20050416000000 Admitted 33
> 20050416000000 Discharged 26
> 20050416000000 Registered 70
> 20050417000000 Admitted 33
> 20050417000000 Discharged 21
> 20050417000000 Registered 65
> Column I'm interested in Discussing is the first, which is stored in its
> table as a VARCHAR(25) and is called DateID. So, clearly it's not a DATET
IME
> or SMALLDATETIME.
> The first 8 characters represent the yyyymmdd but it's just a string. The
> trailing zeros stored seem to be junk.
> I need todo the SELECT to get that column from today and only the previous
> seven days. Also, I want it formatted in mm/dd/yyyy in my output if
> possible.
> This is the closest I've gotten:
> Select DateID
> from DispositionCount
> WHERE ((SUBSTRING(DateID,1,4) = DATEPART(year,GETDATE())) and (SUBSTRING
> (DateID,5,2) = DATEPART(month,GETDATE()))) and (DATEDIFF(day, SUBSTRING
> (DateID,7,2), DATEPART(day,GETDATE()))<= 7)
> Can anyone tell me how to do this? Getting the DBA to change the column to
a
> proper datetime is not feasible.
> Thanks,
> hbcp|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
I believe I'd do it this way - create a derived table that acts as my
own special View (since the DBA is so tight):
SELECT DateID, Status, Tally
FROM
(SELECT LEFT(DateID,8) As DateID, Status, Tally
FROM DispositionCount) As A
WHERE DateID BETWEEN CONVERT(VARCHAR(10),CURRENT_TIMESTAMP-7,112)
AND CONVERT(VARCHAR(10), CURRENT_TIMESTAMP,112)
Substitute the correct column names for the ones I used.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/ AwUBQmVLHoechKqOuFEgEQJ1sACgtQThI8u3Vt5W
ILgEnFdsoU9d9V8An04W
o1H4Q/Gf0Z2e3AjCDugl6m/Q
=ykSG
--END PGP SIGNATURE--
hbcp_1 wrote:
> Hi folks,
> New to SQL programming and reading about CONVERT, CAST and the DATE
> functions aren't giving me enough info. to solve my problem.
> My data looks like this:
> 20050416000000 Admitted 33
> 20050416000000 Discharged 26
> 20050416000000 Registered 70
> 20050417000000 Admitted 33
> 20050417000000 Discharged 21
> 20050417000000 Registered 65
> Column I'm interested in Discussing is the first, which is stored in its
> table as a VARCHAR(25) and is called DateID. So, clearly it's not a DATET
IME
> or SMALLDATETIME.
> The first 8 characters represent the yyyymmdd but it's just a string. The
> trailing zeros stored seem to be junk.
> I need todo the SELECT to get that column from today and only the previous
> seven days. Also, I want it formatted in mm/dd/yyyy in my output if
> possible.
> This is the closest I've gotten:
> Select DateID
> from DispositionCount
> WHERE ((SUBSTRING(DateID,1,4) = DATEPART(year,GETDATE())) and (SUBSTRING
> (DateID,5,2) = DATEPART(month,GETDATE()))) and (DATEDIFF(day, SUBSTRING
> (DateID,7,2), DATEPART(day,GETDATE()))<= 7)
> Can anyone tell me how to do this? Getting the DBA to change the column to
a
> proper datetime is not feasible.|||Thanks! Not quite, but I can see it's closer... some syntax error marking at
'And'?
Is DateName a constant or declaration of a variable on the fly?
"CBretana" wrote:
> Try This...
> Select ... Convert(VarChar(10), Cast(Left(DateID, 8) As DateTime), 101)
> DateName
> From ...
> Where Left(DateID, 8) Between DateAdd(day, -7, getdate() And getdate()
> "hbcp_1" wrote:
>|||Untested:
select Select DateID
from DispositionCount
WHERE cast(left(DateID,8) as datetime) >= convert(datetime, dateadd(d, -7,
getdate()), 112)
((SUBSTRING(DateID,1,4) = DATEPART(year,GETDATE())) and (SUBSTRING
> (DateID,5,2) = DATEPART(month,GETDATE()))) and (DATEDIFF(day, SUBSTRING
> (DateID,7,2), DATEPART(day,GETDATE()))<= 7)
cast(left('20050416000000',8) as datetime)
"hbcp_1" <hbcp_1@.discussions.microsoft.com> wrote in message
news:633B8157-4016-4BDF-A552-FE87BCA7C23F@.microsoft.com...
> Hi folks,
> New to SQL programming and reading about CONVERT, CAST and the DATE
> functions aren't giving me enough info. to solve my problem.
> My data looks like this:
> 20050416000000 Admitted 33
> 20050416000000 Discharged 26
> 20050416000000 Registered 70
> 20050417000000 Admitted 33
> 20050417000000 Discharged 21
> 20050417000000 Registered 65
> Column I'm interested in Discussing is the first, which is stored in its
> table as a VARCHAR(25) and is called DateID. So, clearly it's not a
> DATETIME
> or SMALLDATETIME.
> The first 8 characters represent the yyyymmdd but it's just a string. The
> trailing zeros stored seem to be junk.
> I need todo the SELECT to get that column from today and only the previous
> seven days. Also, I want it formatted in mm/dd/yyyy in my output if
> possible.
> This is the closest I've gotten:
> Select DateID
> from DispositionCount
> WHERE ((SUBSTRING(DateID,1,4) = DATEPART(year,GETDATE())) and (SUBSTRING
> (DateID,5,2) = DATEPART(month,GETDATE()))) and (DATEDIFF(day, SUBSTRING
> (DateID,7,2), DATEPART(day,GETDATE()))<= 7)
> Can anyone tell me how to do this? Getting the DBA to change the column to
> a
> proper datetime is not feasible.
> Thanks,
> hbcp|||CBretana -- THANKS, just was missing a parenthesis...
Much obliged. Now I can backtrack through the help to learn what you taught
me. :-)
"CBretana" wrote:
> Try This...
> Select ... Convert(VarChar(10), Cast(Left(DateID, 8) As DateTime), 101)
> DateName
> From ...
> Where Left(DateID, 8) Between DateAdd(day, -7, getdate() And getdate()
> "hbcp_1" wrote:
>|||Thanks, will try all three suggestions. I'm not only using the query in SQL
Query Analyzer, it's actually being executed by another software product
(Java-based) and alas... the first option didn't work in that product. Need
to include the slashes too...
"Raymond D'Anjou" wrote:

> Untested:
> select Select DateID
> from DispositionCount
> WHERE cast(left(DateID,8) as datetime) >= convert(datetime, dateadd(d, -7
,
> getdate()), 112)
> ((SUBSTRING(DateID,1,4) = DATEPART(year,GETDATE())) and (SUBSTRING
> cast(left('20050416000000',8) as datetime)
> "hbcp_1" <hbcp_1@.discussions.microsoft.com> wrote in message
> news:633B8157-4016-4BDF-A552-FE87BCA7C23F@.microsoft.com...
>
>|||I was making a mistake elsewhere, I've got it perfect now. CBretana's works
best. It's exactly what I wanted and clean, efficient code. THANKS everyon
e.
"hbcp_1" wrote:
> Thanks, will try all three suggestions. I'm not only using the query in S
QL
> Query Analyzer, it's actually being executed by another software product
> (Java-based) and alas... the first option didn't work in that product. Ne
ed
> to include the slashes too...
> "Raymond D'Anjou" wrote:
>|||Since getdate() includes a time portion.
Also, a lot of people in this forum find it less intuitive to use Between
with dates:
(I'm not looking for a fight CBretana)
Select ... Convert(VarChar(10), Cast(Left(DateID, 8) As DateTime), 101)
DateName
From ...
Where Left(DateID, 8) >= CONVERT(DATETIME, DateAdd(day, -7, getdate()), 112)
And Left(DateID, 8) <= CONVERT(DATETIME, getdate(), 112)
"hbcp_1" <hbcp_1@.discussions.microsoft.com> wrote in message
news:1016A71C-28F8-4E9D-A51B-F1DACCEFFF96@.microsoft.com...
>I was making a mistake elsewhere, I've got it perfect now. CBretana's works
> best. It's exactly what I wanted and clean, efficient code. THANKS
> everyone.
>
> "hbcp_1" wrote:
>|||Yes, sorry, missing Parentheses!
"hbcp_1" wrote:
> CBretana -- THANKS, just was missing a parenthesis...
> Much obliged. Now I can backtrack through the help to learn what you taug
ht
> me. :-)
> "CBretana" wrote:
>