I don't know why my company did this, but dates are being stored in a char field within our database. Meanwhile, I've been setting up new pages using datetime. That's just a little back story. My question is, is it possible to change the format of all dates in the table from yyyy/MM/dd to MM/dd/yyyy in the char field? I'm just trying to think of an easier way to change a thousand or so records instead of doing it manually. Thanks.
I'm totally new at SQL Server, I'm sorry if this question looks very simple, but I just don't know how to change the datetime value in a field on my database.
I'm working in vb.net and I have a datetime field in sql server, I can store date values passing this value:
DatePick.Value.ToString("s")
dates are saved fine, but if want to make this query:
Select * from backlog where date1>=isdate('21/02/2006') order by date1 asc
I get all the values from that field, no filter is done. Date are shown like this 2004-05-23 14:25:10.000 in the query.
What do I have to do ? do I have to change the date format of my field to ISO 8601 ? how ? do I use a script or what ???????
Please remeber that my sql script should be done from vb.
To be able to tell the Period number ([PD]) to change from an integer to a var_char so that it can be concatenated with the Fiscal Year. I.e. Fiscal Year || Period number to produce the following results.
2006 01
2006 02
2006 03
Etc……
Status of Problem:
The issue is that I can only get it done to the point to where the Fiscal Year || Period number yields the following results:
20061
200610
200611
200612
20062
Etc….
This is as issue since I am trying to get all the information from the past to a certain year and period. Using a filter that says
Fiscal Year + Period Number <= ?Prompt_Fiscal_Year? + ?Prompt_Period_Number?
So if I enter Year: 2007 Period 3
I should get:
2006 01
2006 02
2006 03
Etc…….
2006 11
2006 12
2007 01
2007 02
2007 03
Can you please let me know if my thinking is off or if my SQL is wrong, Thank you for your assistance in this matter.
hi Experts,what is the purpose writing a date in the following format:where x.event_date >= {ts '1980-01-01 00:00:00'}versus like this:where x.event_date >= '1980-01-01 00:00:00'what benifit does it add to later form of writing?Thanks in advance.schal.
ok so this is my table structure [odcCode] [int] NOT NULL , [insCode] [varchar] (11) COLLATE Modern_Spanish_CI_AS NOT NULL , [odcQty] [int] NOT NULL , [odcCostoUnitario] [numeric](18, 4) NOT NULL , [odcISV] [bit] NULL , [odcStatusInsumo] [varchar] (3) COLLATE Modern_Spanish_CI_AS NULL , [odcInsArrivalDate] [datetime]
and when I run, the insert command I get the next error: Syntax error converting datetime from character string.
The date is taken from a standar DateTime Picker control from Visual Studio 2003 and I can't change the regional settings on the computers (that's not an option)
What can I do to fix the problem and be able to insert the date in any format?
I have a need to display the difference between two dates, a start date and a end date in the format HH:mm where the hours could be greater than 60.
For example:
Start Date - 30/01/2007 09:00:01 End Date - 01/02/2007 20:40:04
When i use the following code (=Fields!dateend.Value - Fields!DateStart.Value) i get 2.11:40:03 which i can easily understand, but the customer wants it as above!
I'm currently having problems exporting formatted dates from reporting services 2005 to excel.
Basically what I require is a way to format a date in reporting services so that it only shows the date without the time (preferably british format) and when it is exported to excel it is still formatted as a date.
This is so the user can sort the data file via date, I appreciate it is easy to select the column and format the cells but i would prefer to have a 'cleaner' solution to this problem which avoids the need for users to be formatting exported reports.
Originally I was formatting the dates as convert(varchar,@date,103) in the SP which converts it to a character string and excel picks this up as a character as would be expected. So I changed this to a date and set about trying to format the date in Reporting Services, so far i've been unsuccesfull using cdate (brings back the time) and format as it again converts it to a character string.
I am having the "classical problem" of the forums; A local date changed to the american format (normally in the development environment) which I call "Switching months with days"... well it switches both again if you press "view report" again :)The problem I'm having is that when I Navigate from one report to other, the dates get switched... Everything's been set in the locale uk date format (dd/mm/aaaa), in the operating system, in the database and in the reports... and the reports are working properly through the web interface.. the only thing that is not working properly is the Navigation which switches the date month with the day...Changing all the Reporting Services server, database server to the american format date is not an acceptable solution. Thanks for any guidance on this, as I'm pretty lost...Jose
I am importing a couple SAS datasets to SQL Server 2008 for a project. The dates are in a float format, they show up as DT_R8 in SSIS. How can I convert these values to SQL server datetime? I have tried dozens of methods I found on-line with no success, I keep getting 'Arithmetic overflow error converting expression to data type datetime.' errors.
I have created range bar chart and I am not able to achieve the following tasks.
1. Change X-axis Label Format to Quarter:
I have x-axis with dates and y axis of project groups. I have changed x-axis interval type = month and interval=3.
Set the Maximum = Max(ProjectEndDate) and Minimum = Min(ProjectStartDate).
Now my chart showing 3 months x-axis interval dates in mm/dd/yyyy format. I want to change this interval date format to Quarter. The problem is LabelsFormat property is not recognize the "=Q or q or quarter" and also not accepting the expressions. How can I achieve this?
2. Placing series side by side when it is not overlapping
I want to place the same group series side by side only when the previous project end date is less than next project start date, otherwise place the next project to next row. How can I achieve this?
Hi, I need to automate the procedure of selecting column with numeric and passing those column values as string to another stored procedure.
Here is sample code : CREATE procedure procdeure1 @Utility varchar(50) WITH RECOMPILE as if @Utility='Electricity' begin IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'gmmers1') DROP TABLE gmmers1 IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'gmmers2') DROP TABLE gmmers2 create table gmmers1(sitecode varchar(15), Gen_Electricity_Usage bigint ) create table gmmers2 (gmmerssitecode varchar(15), Gmers_Electricity_Usage bigint ) insert into gmmers1 Select site.Sitecode,sum(isnull(AcctRptdata.ElectricityUse,0)*factor) as 'Electricity Usage' From GEN..AcctRptdata AcctRptdata, GEN..site site,SuperAccesslevels.dbo.convfactor,SuperAccesslevels.dbo.countrysettings Where ((AcctRptdata.Year*100)+AcctRptdata.Month) >= 200511 and --((AcctRptdata.Year*100)+AcctRptdata.Month) < year(DATEADD(m,-1, GetDate()))*100+month(DATEADD(m,-1, GetDate())) and ((AcctRptdata.Year*100)+AcctRptdata.Month) >= 200511 and ((AcctRptdata.Year*100)+AcctRptdata.Month) <= 200707 and site.idsite = AcctRptdata.siteid and site.sitecode not like ('C%') and len(sitecode ) = 8 and AcctRptdata.idsvc in (100) and SuperAccesslevels.dbo.convfactor.[Default] = SuperAccesslevels.dbo.countrysettings.IdUnitElec and SuperAccesslevels.dbo.countrysettings.IdCountrySetting = Site.IdCustomerSetting and [user] = 1 and site.Sitecode not like '%B%' and site.sitecode not like '9999%' and AcctRptdata.ElectricityUse >0 --Added on 16th Aug and site.sitecode in (select left (sitecode,8) from GEN..site where len(sitecode) >8)--= 11) --and site.sitecode in (select left(sitecode,8) from gmers_prodn..facility_data where len(sitecode) = 11) Group by site.Sitecode having sum(AcctRptdata.ElectricityUse*factor) > 0 Order by site.Sitecode
insert into gmmers2 select left (sitecode, 8) BU, sum(isnull(KWh_Purchased_Quantity, 0 )) as 'electric use' from gmers_prodn..electricity_data where sitecode in --(select sitecode from facility_data where left (sitecode ,8) in (select sitecode from gen..site where sitecode not like 'C%' and len(sitecode ) > 8 ) -- and len (sitecode) = 11) and rpt_dt >= '2005-11-01' and rpt_dt < '2007-08-01' --and sitecode like 'A0916323%' and sitecode not like '%B%' and left(sitecode,8) not in ('N0010024','N0010088','N0010101','N0010173', 'N0010373','N0010447') and sitecode not like '9999%' group by left (sitecode, 8) order by left (sitecode, 8) -- yyyy-mm-dd
select *,(Gen_Electricity_Usage-Gmers_Electricity_Usage)as Diff from gmmers1,gmmers2 where gmmers1.sitecode=gmmers2.gmmerssitecode and (Gen_Electricity_Usage-Gmers_Electricity_Usage) <>0 end else if @UTILITY='GAS' begin IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'gengas') DROP TABLE gengas IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'gmmersgas') DROP TABLE gmmersgas create table gengas(sitecode varchar(15), Gen_Gas_usage bigint ) create table gmmersgas (gmmerssitecode varchar(15), Gmers_Gas_Usage bigint ) insert into gengas Select site.Sitecode,sum(isnull(AcctRptdata.NaturalGasUse,0)*factor) as 'Gas Usage' From GEN..AcctRptdata AcctRptdata, GEN..site site,SuperAccesslevels.dbo.convfactor,SuperAccesslevels.dbo.countrysettings Where ((AcctRptdata.Year*100)+AcctRptdata.Month) >= 200511 and --((AcctRptdata.Year*100)+AcctRptdata.Month) < year(DATEADD(m,-1, GetDate()))*100+month(DATEADD(m,-1, GetDate())) and ((AcctRptdata.Year*100)+AcctRptdata.Month) >= 200511 and ((AcctRptdata.Year*100)+AcctRptdata.Month) <= 200707 and site.idsite = AcctRptdata.siteid and site.sitecode not like ('C%')and len(sitecode ) = 8 and AcctRptdata.idsvc in (200,300) and SuperAccesslevels.dbo.convfactor.[Default] = SuperAccesslevels.dbo.countrysettings.IdUnitGas and SuperAccesslevels.dbo.countrysettings.IdCountrySetting = Site.IdCustomerSetting and [user] = 61 and site.sitecode not like '%B%' and site.sitecode not like '9999%' and site.sitecode in (select left (sitecode,8) from GEN..site where len(sitecode) >8) and AcctRptdata.NaturalGasUse >0 ----Added on 16th Aug --and site.sitecode in (select left(sitecode,8) from gmers_prodn..facility_data where len(sitecode) = 11) Group by site.Sitecode having sum(AcctRptdata.NaturalGasUse*factor) > 0 Order by site.Sitecode
insert into gmmersgas select left( sitecode, 8 ) BU , sum(Utility_Natural_Gas_Volume) as 'gas use' from GMERS_PRODN..fuel_data where sitecode in --(select sitecode from facility_data where left (sitecode,8) in (select sitecode from gen..site where sitecode not like 'C%' and len(sitecode ) > 8 ) -- and len(sitecode )= 11 ) and rpt_dt >= '2005-11-01' and rpt_dt < '2007-08-01' and sitecode not like '%B%' and sitecode not like '9999%' group by left( sitecode, 8 ) order by left( sitecode, 8 )
select *,(Gen_Gas_usage-Gmers_Gas_Usage)as Diff from gengas,gmmersgas where gengas.sitecode=gmmersgas.gmmerssitecode and (Gen_Gas_usage-Gmers_Gas_Usage)<>0 end
My aim is to pass sitecode having difference <>0 and from date and todate as an parameter to another stored procedure which updates sitewise for the utility so that in case a particular sitecode with same date range is included in one utility it should not be repeated in another utility.
If I am taking a Matrix and right clicking on the column header and click on the SubTotal then it always place that column on the right of it .If I want to place that column to the left of my original column then I can't do it.
Adding manual column and then puuting the Expresstion =Sum(Fields!MyCol.Value) is not halping as it will give me the same value that is there in the column instead of giving me the column
I'm in a middle of a project where replication established between Oracle 8i and SQL server 2005. Now we need to drop one column from on of the tables replicated from Oracle side. My question : Is there anyway I can do this in Oracle and automatically reflected on SQL server? If not what is the proper steps to do it. Realy appreciate your fast response.
How can I do this with Parameters? I can get a single parameter to filter for a single date (or even a combo list of the dates in DB). But I want my parameters to interact so that they specify a range. Is this possible?
Today I have got one scenario to calculate the (sum of days difference minus(-) the dates if the same date is appearing both in assgn_dtm and complet_dtm)/* Here goes the table schema and sample data */
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[temp_tbl]') AND type in (N'U')) DROP TABLE [dbo].[temp_tbl] GO CREATE TABLE [dbo].[temp_tbl]( [tbl_id] [bigint] NULL, [cs_id] [int] NOT NULL, [USERID] [int] NOT NULL,
I have a table that has hotel guests and their start stay date and end stay date, i would like to insert into a new table the original information + add all days in between.
I want to know if there is a way to compare dates in the sql statement with dates that I input into a database and todays date. the datatype that I'm using is smalldatetime.The statement I used is:Select Date from Table where Date > 'Today.now'I get an errorCould this be done or is there another approach?
I have created SSRS report which has many overlapping objects, the output in PDF format seems to good but in word format it is not giving the required output.
I have date coming to one page as a string in the following format"May 4 2005 12:00AM" I need to query one of my tables using this date in combination of other nondate values. How can I convert this date into valid sql server datetime format before I query a database tables Please help
I have a table which stores date-of-birth in varchar 19861231(yyyymmdd). A view takes this data. I want to store this date as mmddyyyy in the view. How can we achieve this?
I have a set of csv files and a set of Format Specification files for each of the csv files. I need to convert the csv files into another format of csv files as specified in the Format Specification files. All the columns of the input csv files do not have a mapping with the columns of the output csv files. How can I achieve this using SSIS ? This is an urgent requirement. Please reply asap. Thanks.
I am stuck at one place, where I have to convert CSV format file data into SAP IDOC format file. In SSIS we don't have any such SAP adapter (though we have .NET Data Provider for mySAP suite [SSIS SAP Adapter] but this is still not fully supported by Microsoft, plus it doesn't have feature to convert data into IDOC format) that can do this. Can someone here please provide me some pointers on any third party adapters available in market to do this job or if anyone has already developed some custom approach to achieve this task?
Your quick response on this is highly appreciated.
I have a table which records employees'time-off records. There are 6 columns in this TimeOff table. They are RequestID, EmpName, StartDate, EndDate, Type, NumofDays. I have another table which has all the dates from 01/01/1950 to 01/01/2056.
I am trying write a query which lists all the dates between the timeoff startdate and enddate, including the the start and end dates, but my query so far only lists the start and end date in a timeoff record:
SELECT D.[Date], Datename(dw,D.[Date]) AS Weekday FROM Dates D LEFT JOIN TimeOff T ON D.[Date] = T.OffStartDate OR D.[Date] = T.OffEndDate WHERE (OffType = 'Sick Day' AND EmpName = 'Cat White') AND (D.[Date] BETWEEN T.StartDate AND T.EndDate)