SQL Query - DateTime - Percentage Between Two Dates For A Year (Jan. 01 - Dec. 31)
Jan 14, 2008
Hello,
I need to find the percentage of a a given contract start and end date for the year given.
For example, the contract_start date is 05/08/2000 and the contract_end date is 04/30/2010, of course this will be 100% if you want to find the percentage for year 2008
but if you wanted to find the percentage for year 2010, then the percentage would be something like 42% (appr. 5 months) (b/c it would for year 2010, the contract would be from 01/01/2010 thru 04/30/2010)
I need to find the percent from the beginning of the year, to the end.
a few examples:
start: 01/01/2007 end: 05/01/2007 if for year: 2007; this is 4 months @33.33%
start: 05/01/ 2006 end: 06/01/2007 if for year: 2007, then 6 months @ 50% (01/01/2007 - 06/01/2007); but if it was for year 2006 then it would be 7 months @ 58% (05/01/2006 thru 12/31/2006)
start: 01/01/2000 end: 03/01/2010 for year: 2008 then 12 months @ 100%
Any help would be valued. Thank you!
View 4 Replies
ADVERTISEMENT
Mar 27, 2015
I'm trying to generate a report using matrix like this
Month
Product PreviousYearSalesAmount SelectedYearSalesAmount %SalesDifference
I can populate year sales amount, but i cant calculate the percentage.
Note: Month and Year are passed as parameters.
View 5 Replies
View Related
Nov 30, 2011
I have to find the earliest date for any existing calendar year in a table...
For instance.....
ClientID Year
1 1/1/2000
1 2/1/2000
2 3/1/2000
2 4/1/2001
2 5/1/2001
The results I need are....
ClientID Year
1 1/1/2000
2 3/1/2000
2 4/1/2001
It is all contained in one table. I have got the earliest years by using the YEAR() function and grouping by it. The only problem is that I am having a problem joining the table back onto itself with the subselect because of it's an aggregate.
Here is the first join I have....
SELECT DT.ClientID, Year1 FROM
(
SELECT ClientID, YEAR(MyDate) as Year1
FROM MyTable
) AS DT
GROUP BY ClientID, Year1
ORDER BY ClientID, Year1
I want to use that as my derived table and then join back to it... but it's not working...
View 1 Replies
View Related
Feb 28, 2008
I'm trying to generate this query, that displays Budget Current Year , Actual Current Year and Prior Year Revenue. When It comes to the Budget and Actual everything works fine, however when I try to add the query for the Prior Year I get an error, and I realized that the leap date is causing the error
Here is what I'm trying to generate
InnCodeID
Quarterly
Monthly
Days
Period
Year
BARmRev
AARmRev
PYRmRev
ADDIS
Q1
Jan
1
1
2008
NULL
NULL
ADDIS
Q1
Jan
1
1
2008
3462.14
5107.65
ADDIS
Q1
Jan
1
1
2008
NULL
NULL
ADDIS
Q1
Jan
1
1
2008
NULL
NULL
Here is the error that I'm getting:
Code Snippet
Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
(4834 row(s) affected)
Here is my Transact-SQL Syntax (summarized because I Couldn't post it):
SELECT
(CASE WHEN (CASE WHEN dbo.Trans.Tr_Dept = '10' AND dbo.Trans.TR_Main = '5120' AND dbo.Trans.tR_sub = '01'
AND Year(dbo.Trans.TR_Date) = Year(dbo.CurrentDate.CurrDate) AND dbo.trans.Datatype = '1'
THEN dbo.trans.Tr_Amount ELSE NULL END) IS NOT NULL THEN
(SELECT Trans1.TR_Amount
FROM dbo.Trans Trans1
WHERE Trans1.TR_Dept = '10' AND TR_Main = '5120' AND TR_Sub = '01' AND trans1.TR_Date = CAST((CAST(Month(dbo.Trans.TR_Date)
AS varchar(2)) + '/' + CAST(Day(dbo.Trans.TR_Date) AS varchar(2)) + '/' + CAST(Year(dbo.CurrentDate.CurrDate) AS varchar(4))) AS datetime)
AND Trans1.TR_Entity = dbo.Trans.TR_Entity AND trans1.datatype = dbo.Trans.DataType) ELSE NULL END) * - 1 AS BARmRev,
--AA Script Here AS AARmRev,
(CASE WHEN (CASE WHEN dbo.Trans.Tr_Dept = '10' AND dbo.Trans.TR_Main = '5120' AND dbo.Trans.tR_sub = '01' AND Year(dbo.Trans.TR_Date)
= Year(dbo.CurrentDate.CurrDate) AND dbo.trans.Datatype = '1' THEN dbo.trans.Tr_Amount ELSE NULL END) IS NOT NULL THEN
(SELECT SUM(Trans1.TR_Amount)
FROM dbo.Trans Trans1
WHERE RIGHT(RTRIM(Trans1.TR_Dept), 2) = '10' AND Trans1.TR_Main = '5120' AND Trans1.TR_Sub NOT BETWEEN '04' AND '05' AND
trans1.TR_Date = CAST((CAST(Month(dbo.Trans.TR_Date) AS varchar(2)) + '/' + CAST(Day(dbo.Trans.TR_Date) AS varchar(2))
+ '/' + CAST(Year(dbo.CurrentDate.CurrDate)-1 AS varchar(4))) AS datetime) AND Trans1.TR_Entity = dbo.Trans.TR_Entity AND
trans1.datatype = '0') ELSE NULL END) * - 1 AS PYRmRev
FROM dbo.EntityDef INNER JOIN
dbo.Trans ON dbo.EntityDef.ED_Property_ID = dbo.Trans.TR_Entity INNER JOIN
dbo.CurrentDate INNER JOIN
dbo.DimTime ON YEAR(dbo.DimTime.TimeDate) = YEAR(dbo.CurrentDate.CurrDate) ON dbo.Trans.TR_Date = dbo.DimTime.TimeDate
WHERE (dbo.EntityDef.ED_Property_ID = 'ADDIS')
ORDER BY dbo.EntityDef.ED_Property_ID, dbo.DimTime.TimeDate
I appreciate all your help
Thanks
View 13 Replies
View Related
Aug 4, 2015
I'm trying to creating the following matrix in SSRS 2008R2 (with more product categories than shown here)The matrix only shows the last two year per product.
The matrix in the report builder looks like this:
For me it's unclear what the expression should be. (or perhaps I need to make a calculation in my TSQL?)
As Row Groups in the matrix I've got:
Product; Year
As Column Groups i've got Month
I can't get it to work. Previous doesn't seem to work in this case (only when I got a total of each year (e.g. one column instead of 12))
View 6 Replies
View Related
Mar 11, 2014
I need to calculate “NET_SALES” and “MARGIN_PERCENT” for each month of the current year … the following returns the same values for each month in the list, which are for the current month. Taking out the GROUP BY line works fine for an overall number.
SALES_MONTH, NET_SALES, MARGIN_PERCENT
January, 1246627.69, 24
February, 1246627.69, 24
March, 1246627.69, 24
-------------------------------------------------
DECLARE @NetSales DECIMAL(18,6)
DECLARE @Cost DECIMAL(18,6)
SELECT
@NetSales = sum(IL.MERCHANDISE+IL.TAX)
,@Cost = sum(IL.COST)
FROM INVOICELINE IL
[Code] .....
View 2 Replies
View Related
Feb 7, 2008
This code displays dates, File name, and File size for four seperate dates 11/20/2007 , 11/30/2007, 12/30/2007 and 01/31/2007 . I'm trying to show the percentage growth from date to date (ie 11/20/2007 -11/30/2007 percentage growth)
is there a way i can get the previous date file size for each entry, so i can have a variable for the calculation. Or i can get the calculate it within this code (ie database_size_mb / ((database_size_md ) where database_size_datetime -1) *100
or whatever the formula is for percentage growth.
Code Snippet
SELECT
Database_Size_Datetime,
Database_file_name,
Database_Size_Mb
FROM RC_STAT.dbo.Tbl_Database_Statistics AS Tbl_Database_Statistics_1
GROUP BY Database_Size_Datetime, Database_file_name, Database_Size_Mb
this is what it displays now:
2007-11-20 00:00:00.000 ACTReplication_Data 442.5000
2007-11-30 00:00:00.000 ACTReplication_Data 442.5000
2007-12-31 00:00:00.000 ACTReplication_Data 442.5000
2008-01-31 00:00:00.000 ACTReplication_Data 442.5000
2007-11-20 00:00:00.000 ACTReplication_Log 14.8125
2007-11-30 00:00:00.000 ACTReplication_Log 109.7500
2007-12-31 00:00:00.000 ACTReplication_Log 112.9375
2008-01-31 00:00:00.000 ACTReplication_Log 115.5625
2007-11-20 00:00:00.000 BAMArchive 0.6875
2007-11-30 00:00:00.000 BAMArchive 0.6875
2007-12-31 00:00:00.000 BAMArchive 0.6875
2008-01-31 00:00:00.000 BAMArchive 0.6875
2007-11-20 00:00:00.000 BAMArchive_log 0.4922
2007-11-30 00:00:00.000 BAMArchive_log 0.4922
2007-12-31 00:00:00.000 BAMArchive_log 0.4922
2008-01-31 00:00:00.000 BAMArchive_log 0.4922
View 1 Replies
View Related
Jul 20, 2005
Does anyone have an example of an SQL query which returns rows for theyear-to-date, but where the "year" commences on August 1st?e.g. select * from mytable where datefield > last august 1stTIA for any helpIsabel
View 2 Replies
View Related
Feb 28, 2005
I have a program that calls queries (OLAP system) the system includes a dimension of date: Year, Quater, Month, Week
When the result appears in the table, it is not in order? Only the year is in oredr and after that each heirachy is wrong and not in order....not sure how to do this!!!
any help would be grateful!!! not sure what I should be looking at.....
View 14 Replies
View Related
Apr 2, 2007
Hi all I this stored procedure is suppose to turn give the users the ability to put the month and date in so they can see how many each inspector did for that month and year.
Create Procedure LookupYearMonth
AS
SELECT I.[Last Name], I.[First Name],
[Date by Month] = DATENAME(month, MT.[Date] + ' ' + DATENAME(year, MT.[DATE]),
[Count Of Main Table] = count(*)
FROM Inspectors I
INNER JOIN [Main Table] MT
ON (I.ID = MT.Inspector)
GROUP BY I.[Last Name], I.[First Name],
DATENAME(month, MT.[Date] + ' ' + DATENAME(year, MT.[DATE])
WHERE (MT.[Date] >= CONVERT(datetime, @EnterMonthYear)) AND
(MT.[Date] < DATEADD(month, 1, CONVERT(datetime, @EnterMonthYear)))
GO
View 14 Replies
View Related
May 6, 2014
I am working on some payroll related code which currently has the following hard-coded CASE statement (I won't include the entire thing, it is lengthy):
AND b.TCDateTime BETWEEN '2013-01-01 0:00' and '2013-12-31 23:59'
I want to get rid of the hard coding, and have this use current year dates. So for 2014, it should reference rows where the TCDateTime is >='2014-01-01 0:00' AND <'2015-01-01 0:00'..I think the following would accomplish this, but would like confirmation that this is the 'best' way (and that it will work!)
SELECT CONVERT(DATETIME, CONVERT(CHAR(4), DATEPART(yyyy, GETDATE())) + '0101') AS curryrbegin
--output should be yyyy-01-01 00:00:00.0 where yyyy is current year
SELECT CONVERT(DATETIME, CONVERT(CHAR(4), DATEPART(yyyy + 1, GETDATE()))
+ '0101') AS nextyrbegin
--output s/b nextyear-01-01-00:00:00.0
Then, change the CASE statement to read:
AND (b.TCDateTime >= curryrbegin AND < nextyrbegin)
View 8 Replies
View Related
Jul 23, 2015
I have three tables: EMP (ID, NAME), EMPDATE (ID, STARTDATE, ENDDATE), YEAR(YEAR)
I would like to get the most recent date within a given year per each EMP? For example, EMPID 1 can be enrolled in many programs, each program has start end dates. I need to list the most recent date an employee was enrolled (max date between START AND END DATE which ever is most recent enrollment) for a given year. For example, for 2014 his/her most recent enrollment should be 10/23/2014 for year 2014 and 2013-10-24 for year 2013.
SELECT ID, EMP.NAME, DTE.StartDate, DTE.ENDDATE, year
FROM
EMP_DATE DTE join
EMP_INFO EMP on EMP.ID = DTE.ID join
YEAR YR on YR.YEAR = YEAR(DTE.STARTDATE)
DATA SAMPLE:
EMP
ID NAME
1 JOHN
EMP_INFO
ID STARTDATE ENDDATE
12013-10-24 2014-03-11
12014-06-13 2014-03-11
12014-06-15 2014-03-11
12014-09-08 2014-03-11
12014-09-12 2014-03-11
12014-09-14 2014-03-11
12014-01-13 2014-05-17
12014-05-14 2014-06-09
12014-06-10 2014-06-16
12014-08-31 2014-09-04
12014-09-05 2014-09-06
12014-09-07 2014-10-23
YEAR
Year
2012
2013
2014
2015
View 9 Replies
View Related
May 6, 2015
I am currently working on a T-Sql query(Sql server 2008) to calculate total no of days between date ranges by year
Table:
Start Date End Date
01/01/2013 04/30/2014
11/01/2014 05/31/2015
06/01/2015 12/31/2015
My expected result.
2013 - 365
2014 - 181
2015 - 365
Note:
Date range can span b/w multiple years
Date ranges will not overlap
I just want the total number of days covered by the range for each year.
Is there any simple way to do this calculation.
View 9 Replies
View Related
Oct 24, 2014
I have a column with datetime datatype and I need to create another column in the same table with only the year and another with year-month. How do I write this query
View 8 Replies
View Related
Sep 24, 2015
I have a date dimension set in the SSAS Cube. I have been trying get quarter,year,month,semester start and end dates using ClosingPeriod() and OpeningPeriod() functions but not getting the exact value. How the get correct dates for a given date.
View 2 Replies
View Related
Jul 17, 2001
Hi.. can you please supply a SQL statement which will convert a datetime value to a Month Year format?
2001-07-17 14:32:20.763 ---> July 2001
thankyou !
Jen
View 2 Replies
View Related
Feb 8, 2006
using MS SQL Server, I want to update only the day,month and year portion of a Datetime field.
So, i want to create an update query to set the day, month and year the same in each record but leave the datepart unchanged.
This gives me an error message:
UPDATE dbo.tblMEETINGS
SET DATEPART(dd, MeetingTimeNEW) = 1, DATEPART(mm, MeetingTimeNEW) = 1, DATEPART(yy, MeetingTimeNEW) = 2006
In my mind, an electrician, it make sense to only update each part of the whole. However.........
View 14 Replies
View Related
Jan 21, 2008
Hi,
I have rows with a datetime column which spans many years. I am wondering is there a more simple way to select those rows where the datetime column is in a particular year. For example...
where datetime_column.year = '2007'
I know i can use the 'between' sql etc...but am wondering if theres something more straightforward im not aware of.
Thanks..
View 4 Replies
View Related
May 19, 2008
hai friends,
iam doing a project in .net and using sql server.
i need to compare only month and year part in datetime type to retrive data.
1)retrive unique year and its months available in the database.
like may 2008
apr 2008
mar 2007
View 3 Replies
View Related
Nov 25, 2014
I have a table with a 25,000 records with fields like this:
Jan 1 196
Jun 29 195
Jan 22 196
Sep 17 195
Mar 22 193
Nov 3 197
Is there a quick way to add the zero onto the year, before I convert them into datetime format?
View 3 Replies
View Related
Apr 2, 2008
I have a table with a datetime field 'TheDate'. Currently dates are stored as 'mm-dd-yyyy 00:00:00'. Is there a way to get just the month, day and year parts, '01/01/2008' into the field without changing the field data type to varchar? I'm asking because when I do this:
declare @MyDate as datetime
set @MyDate = '04/02/2008 18:00:00'
select substring(convert(varchar,@MyDate,101),1,10)
I get '04/02/2008', but when I do this:
update TheTable
set TheDate = substring(convert(varchar,TheDate,101),1,10)
I'm still getting a date in the format 'mm-dd-yyyy 00:00:00' stored in the table. I'd like to be able to lose the time portion, but I'd like to be able to keep the datetime datatype for date math purposes. Can it be done?
View 4 Replies
View Related
Jan 12, 2006
Hello All,I've got a DATETIME field, and it includes hour:minutes:second data. I want to do selects where I can simply match on the month, day and year. For instance, something like this:SELECT * FROM QuizAttempts WHERE DateTimeTaken = '1/12/2006'And have it match anything that was taken that day, regardless of *when* it was taken. Any suggestions?Thanks! -Josh
View 2 Replies
View Related
May 8, 2008
In my SSIS package I am trying to connect to a database in Oracle 10.2.0.3 using an Oracle Provider for OLE DB.
I get the following error:
at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
at System.Data.ProviderBase.DbBuffer.ReadDateTime(Int32 offset)
at System.Data.OleDb.ColumnBinding.Value_DBTIMESTAMP()
at System.Data.OleDb.ColumnBinding.Value()
at System.Data.OleDb.OleDbDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.OleDb.OleDbConnectionInternal.GetSchemaRowset(Guid schema, Object[] restrictions)
at System.Data.OleDb.OleDbConnection.GetOleDbSchemaTable(Guid schema, Object[] restrictions)
at System.Data.OleDb.OleDbMetaDataFactory.PrepareCollection(String collectionName, String[] restrictions, DbConnection connection)
at System.Data.ProviderBase.DbMetaDataFactory.GetSchema(DbConnection connection, String collectionName, String[] restrictions)
at System.Data.ProviderBase.DbConnectionInternal.GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, String collectionName, String[] restrictions)
at System.Data.OleDb.OleDbConnection.GetSchema(String collectionName, String[] restrictionValues)
at Microsoft.DataWarehouse.Design.OleDbSchema.GetSchema(String collectionName, String[] restrictionValues)
at Microsoft.DataWarehouse.Design.DataSourceConnection.GetSchemaTable(DataTable& dataTable, String collectionName, String[] restrictions)
at Microsoft.DataWarehouse.Design.DataSourceConnection.ConvertGetSchema(DataTable& dataTable, Guid schemaEnum, Object[] restrictions)
at Microsoft.DataWarehouse.Design.DataSourceConnection.GetSchemaTable(DataTable& dataTable, Guid schemaEnum, Object[] restrictions)
at Microsoft.DataTransformationServices.Design.ComboBoxWithTables.GetTableInfos(DataSourceConnection dataSourceConnection, String connectionName)
at Microsoft.DataTransformationServices.Design.ComboBoxWithTables.FillTableOrViewComboBox()
Why this is not working for 10.2?
The same package works fine for Oracle 8.1.7
THANKS FOR YOUR HELP!
View 5 Replies
View Related
Aug 3, 2007
I have a form that's filtering search results and porting to a gridview. The drop down is selecting from the date column of SQL, but i want it the default value to show all dates in the gridview. In a normal string field, you can just use "%", but a datetime field won't take this. What can i use to show all dates?
View 3 Replies
View Related
Dec 14, 2007
I have a stored procedure to add a poeersons DOB to a table. The date is being stored as Dec 12 1980
Instead of as 12/12/1980
The table uses a datetime data type.
The data type of the date being passed into the stored procedure is also set to datetime. (@DOB datetime) Even though the value passed into the procedure is 12/12/1980 It saves the date as Dec 12 1980
What do I need to do to fix this?
Miranda
View 2 Replies
View Related
Mar 11, 2008
Ok guys, here is my query
GridSqlDataSource1.SelectCommand = "SELECT *, (([WinSum])/(([WinSum]) + ([LossSum]))) AS WinPercent FROM [ResultsView] WHERE ([CDIV] = @CDIV) ORDER BY [CTEAM]"
I need it to give me a 3 decimal percentage for WinPercent, but right now it is giving me 0 because as an example:
6 / 7 = 0 instead of 0.857
Any ideas?
View 10 Replies
View Related
Aug 5, 2007
Hi Guys,
I am in need some uinderstanding of how to return the percentage of calls that were closed, between 1, 2 ,3, 4 and 5 days (possibly extendable to catch all those that were holding on to jobs to make it look like the were busy) as well as including all open jobs.
Because of my newbie status I am stumped at how to even start a query of this magnitude, and no this is not a school assignment :-) just some one who is very new to T-SQL and wanting to learn how to extract data from an MS SQL database server, as I find it fascinating, also my bosses find it fascinating the type of data I am returning for them so far.
So enough waffling.
This query will be run through VBA, any variable(s) will be supplied by VBA.
DB name = Envisage
Table name = HD_Call
Columns = DateRaised (datetime, null), DateCompleted (datetime, null)
Help in understanding how to construct this query will be grately appreciated.
View 13 Replies
View Related
Jun 26, 2007
I have following tables structure
Employee
---------
EMP_ID varchar PK
NAME varchar
DEPARTMENT_CODEvarchar
POSITION_CODEint
Position
--------
POSITION_CODEint PK
POSITION_NAMEvarchar
Department
----------
DEPARTMENT_CODEvarchar PK
DEPARTMENT_NAMEvarchar
Training_Module
---------------
TRA_ID varchar PK
TRA_NAMEvarchar
TRA_GROUPvarchar (three group, A,B and C)
View_Training_Module
--------------------
MV_ID int PK
EMP_ID varchar
TRA_ID varchar
VIEW_DATE datetime
Training_Module table data like this
TRA_ID..TRA_NAME..TRA_GROUP
--------------------------------------
v01SafetyVideo1G1
v02SafetyVideo2G1
v03SafetyVideo3G1
V04SafetyVideo4G2
V05SafetyVideo5G2
v06SafetyVideo6G2
v07SafetyVideo7G3
v08SafetyVideo8G3
v09SafetyVideo9G3
View_Training_Module table data like this
EMP_ID.........TRA_ID....VIEW_DATE
-------------------------------------------
p0006367V016/2/2007
p0006367V026/2/2007
p0006367V036/2/2007
p0003892V016/12/2007
p0003892V026/12/2007
p0003892V036/12/2007
p0003890V016/15/2007
p0003890V026/15/2007
p0003890V036/15/2007
p0001232V046/16/2007
p0001232V056/16/2007
p0001232V066/16/2007
p0001230V076/17/2007
p0001230V086/18/2007
p0001230V096/18/2007
We have 44 Safety training videos (15 minutes)
How can calculate the percentage of each employee in query ?
if emploee view 22 video it means that this employee
50% view the videos.
We have to calcuate
1. total number of video view by each employee, sum
2. each employee perentage of viewing.ie. percentage %
3. Group wise percentage, ?
we have three group A,B,and C, calcuate the each
group percentage in query ?
regards
Martin
View 4 Replies
View Related
Jul 23, 2005
I am trying to figure out the syntax for a query that will essentiallygive me the Percentage each of my areas contributes to the Whole. Iknow this can be achieved by multiple queries but I would like to keepit intact as one single query if possible.For Example I have the following data set--AREA MOUNE 1234SO 4312WE 12312MW 97123NE 1123SO 31WE 312MW 971The results I would like to see would look likeAREA MOU PERCENTMW 98094 .83536NE 2357 .02007WE 12624 .10751SO 4352 .03706The query I came up with is--SELECT DISTINCT Area, SUM(MOU) AS AREA_TOTAL, sum(MOU) /(SELECT SUM(MOU) AS TOTAL_MOUFROM [2004_NOVEMBER_COST])as[PERCENT]FROM [2004_NOVEMBER_COST]GROUP BY AreaAll seems to calculate with the exception of the Percent where all thepercentages are 0's.I think I need to take the first line AREA_TOTAL and now divide by theSUM(MOU) like this--SELECT DISTINCT Area, SUM(MOU) AS AREA_TOTAL, AREA_TOTAL /(SELECT SUM(MOU) AS TOTAL_MOUbut I get Invalid Column.I essence I think it is a simple query but I am hitting a wall. Anyadvice would help.Thanks,Ben
View 3 Replies
View Related
Jul 12, 2006
Hi
I want to create a table that has a datetime column, data type=datetime and I want the date to start form 01/01/2004 00:00:00 to 01/01/2008 00:00:00 the increment will be by minute like
01/01/2004 00:01:00
01/01/2004 00:02:00
01/01/2004 00:03:00 and so on up to 01/01/2008 00:00:00
I will use this time dimension in bussiness objects.
please provide me with the SQL sript to do this.
View 3 Replies
View Related
Dec 9, 2006
Dear All
I have following table
id|name|female
1|John|No
2|Brian|No
3|Tanya|Yes
How can I get percentage of females in this table?
Thanks a lot!
Svirid
View 2 Replies
View Related
Oct 28, 2015
I totally forgot how can I make a percentage. Look at the code below:
create table #acca (name varchar(10), tipo varchar(10), lett int)
insert into #acca values ('Italy','Europe',15), ('France','Europe',10), ('Colombia','America',15), ('Cile','America',75)
select * from #acca
/*Query Number 1 */
select name, tipo, lett, sum(lett) over (partition by tipo) as TotCon,
sum(lett) as Total
from #acca group by name,tipo,lett;
/*Query Number 2*/
with cte as (
select name, tipo, lett, sum(lett) over (partition by tipo) as TotCon,
sum(lett) as Total
from #acca group by name,tipo,lett)
select name, tipo, lett/totcon from cte
Question query number 1: how can I retrieve the absolute total? Sum(lett) over what?
Question query number 2: why lett / totcon retrieves 0?
Question plus: is there a way to retrieve the percentage without using the cte?
View 4 Replies
View Related
Sep 11, 2007
Hi all,
I need to migrate from a DB with a column containing dates as varchar to a new DB which will have a column with the same content as the source DB but in datetime format.
I have tried to use the cast function but i always get a message saying that the conversion result in an out of range error.
Someone can help me? PLEASE
Thanks
View 8 Replies
View Related