Hi,
I have a varchar field named FinancialYTDCode containing data in the format 2007F or 2008F. I want to only select the rows with the FinancialYTDCode that is the same as the current year.
Could someone please show me how I write this in my script.
Thanks
SELECT * FROM PABX INNER JOIN LOGIN ON (PABX.COD_CLIENTE = LOGIN.COD_CLIENTE) AND LEFT(LOGIN.TELEFONE1,3) = LEFT(PABX.NRTELEFONE,3) LEFT JOIN AUXILIAR ON (AUXILIAR.ORIGEM=LOGIN.LOCALIDADE) WHERE pabx.COD_cliente = 224 and SUBSTRING(PABX.NRTELEFONE,4,1) NOT IN ('9', '8', '7') AND LOGIN.UF = RIGHT(PABX.LOCALIDADE,2) AND LOGIN.LOCALIDADE <> PABX.LOCALIDADE AND PABX.CLASSIFICA IS NULL AND PABX.LOCALIDADE <> AUXILIAR.DESTINO AND (BLOQUEADO = 0 OR BLOQUEADO IS NULL)
But It has a problem because when AUXILIAR.DESTINO returns null (it means there is no registry) the condition AND PABX.LOCALIDADE <> AUXILIAR.DESTINO doesn't work, like 'SAO PAULO' is different from 'NULL' but for my query no it's not even equal, and this condition ommit the results....how can I solve it ?
PS: Both auxiliar.destino and pabx.localidade is varchar(255)
Can anyone help me on this!I've got more than a 1000 records in a SQL server database.The problem is that the the date field is set to varchar, and that gives a lot of trouble. (for example by sorting a table, it's a mess)How can i make sure that i will have a table with the date field set to datettime en that those 1000 records still will be in it. thanks in advance!
select convert(datetime,'04-20-' + right(term,4)) as dt, 'Deposit' as type, a.* from dbo.status_view a
where right(term,4) always returns a string which constitutes a 4 digit year eg '1999','2004',etc.
The SQL above returns
2004-04-20 00:00:00.000 Deposit ...
Which makes me think that it is able to successfully construct the datetime object inline. But then when I try and do:
select * from ( select convert(datetime,'04-20-' + right(term,4)) as dt, 'Deposit' as type, a.* from dbo.status_view a ) where dt >= a.submit_date
I get the following error:
Syntax error converting datetime from character string.
Given that it executes the innermost SQL just fine and seems to convert the string to a datetime object, I don't see why subsequently trying to USE that datetime object for something (in this case comparison with submit_date which is a datetime in the table a) should screw it up. Help!!! Thanks...
I have a table with a DateTime field that has Dates in the format of mm/dd/yyyy I want to do a simple count on the table for the previous day but keep getting 0 for the results. Here is the script I've been trying.
SELECT COUNT(*) FROM mytbl WHERE Collected_Date = DateAdd (dd, -1, GetDate())
It appears to me that the time portion of the DateAdd function keeps the matches that I am looking for from happening. What am I missing or am I going about this all wrong?
I am trying to return all records between 2 dates. The Date columns are in DateTime format, and i am ignoring the timestamp. The user should be able to input UK Date Format (dd/mm/yyyy) and return the rows. This sql code works fine for American date format, but i get an error: converting from varchar to datetime when i put in a UK format. eg. 22/11/06. Please advise on this problem! many thanks!
ALTER PROCEDURE SalaryBetweenDates (
@WeekStart datetime,
@WeekEnd datetime ) AS
BEGIN SET @WeekStart = (SELECT REPLACE(CONVERT(DATETIME,@WeekStart ,103),' ','-')) SET @WeekEnd = (SELECT REPLACE(CONVERT(DATETIME,@WeekEnd ,103),' ','-')) END
BEGIN SELECT s.StaffNo,s.StaffName,s.StaffAddress, s.HourlyRate, sh.HoursWorked, CONVERT(varchar(12), sh.WeekStart, 103) AS StartDate, CONVERT(varchar(12), sh.WeekEnd, 103)As EndDate,(sh.HoursWorked * s.HourlyRate)"Salary" From Staff As S INNER JOIN StaffHours As Sh On S.StaffNo = Sh.StaffNo WHERE sh.WeekStart >= (@WeekStart) AND sh.WeekEnd <= (@WeekEnd)
FOR XML RAW ('paySlip'), root('Staff'), ELEMENTS XSINIL END
sorry folks the other message was on the wrong board!
Hello friends,
I am trying to return all records between 2 dates. The Date columns are in DateTime format, and i am ignoring the timestamp. The user should be able to input UK Date Format (dd/mm/yyyy) and return the rows. This sql code works fine for American date format, but i get an error: converting from varchar to datetime when i put in a UK format. eg. 22/11/06. Please advise on this problem! many thanks!
ALTER PROCEDURE SalaryBetweenDates (
@WeekStart datetime,
@WeekEnd datetime ) AS
BEGIN SET @WeekStart = (SELECT REPLACE(CONVERT(DATETIME,@WeekStart ,103),' ','-')) SET @WeekEnd = (SELECT REPLACE(CONVERT(DATETIME,@WeekEnd ,103),' ','-')) END
BEGIN SELECT s.StaffNo,s.StaffName,s.StaffAddress, s.HourlyRate, sh.HoursWorked, CONVERT(varchar(12), sh.WeekStart, 103) AS StartDate, CONVERT(varchar(12), sh.WeekEnd, 103)As EndDate,(sh.HoursWorked * s.HourlyRate)"Salary" From Staff As S INNER JOIN StaffHours As Sh On S.StaffNo = Sh.StaffNo WHERE sh.WeekStart >= (@WeekStart) AND sh.WeekEnd <= (@WeekEnd)
FOR XML RAW ('paySlip'), root('Staff'), ELEMENTS XSINIL END
hi, How do i convert a varchar field into the datetime data type? the reason i need this lies in the requirement that in the earlier data base the column that is hlding the date value is having the data type as varchar. and in the new design the column data type is datetime. i am using sql scripts for the data migration from the older design to the newer and got stuck with this datetime convertion issue. do let me know the best possible solution.
following are the sample data that is theer in the older table for the date.
12/12/2003 1/13/2007 01132004 1-1-2004 1.2.2001
there is no uniformity of the data that is stored currently.
Is there a performance impact (if so, how great is it) when comparing a date to a datetime data type?
An educated guess suggests yes, as there will be a type casting... but then again I don't believe there's an issue when comparing an int to a tinyint and there's an assumption these would play by the same rules?
This has only come about because I'm considering changing the data type used in my standard calendar script and this popped in to my head.
I have a table with a column that is currently a varchar(50), but I want to convert it into an int. When I try to just change the type in design mode I get an error that conversion cannot proceed. When I look at the field it appears some of the entries have special characters appended at the end, I see a box after the value.
How can I remove all speical characters and then convert that field to an int?
Also I tried the following query which did not work as well, same error about conversion.
Hi all, having a little problem with saving dates to sql databaseI've got the CreatedOn field in the table set to datetime type, but every time i try and run it i get an error kicked up Error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.The statement has been terminated."I've tried researching it but not been able to find something similar. Heres the code: DateTime createOn = DateTime.Now;string sSQLStatement = "INSERT INTO Index (Name, Description, Creator,CreatedOn) values ('" + name + "','" + description + "','" + userName + "','" + createOn + "')"; Any help would be much appreciated
I am trying to drag data from Informix to Sql Server. When I kick off the package using an OLE DB Source and a SQL Server Destination, I get DT_DBDATE to DT_DBTIMESTAMP errors on two fields from Informix which are date data ....no timestamp part
I tried a couple of things:
Created a view of the Informix table where I cast the date fields as datetime year to fraction(5), which failed.
Altered the view to convert the date fields to char(10) with the hopes that SQL Server would implicitly cast them as datetime but it failed.
I have an excel spreadsheet that only has email addresses in a single columnar format on it (318 emails). I want to check and see if any of those emails are in the database. Is there a easier way than having to enter 300+ "OR" statements?
SELECT "Name"."FIRST_NAME", "Name"."LAST_NAME", "Name"."EMAIL", "Name"."ID", "Name"."MEMBER_TYPE" FROM "APSCU_PROD"."dbo"."Name" "Name" WHERE Name.EMAIL='marie@bahoo.com' OR Name.EMAIL='markg@ts.com' OR Name.EMAIL='mare@t.edu'
Hi: I have a column call Date_Sent (28/02/2004)(dd/mm/yyyy) format as varchar at beginning. I want to convert to other column as datetime. I use Query like: SELECT CAST(SUBSTRING(Date_Sent,1,2)as int) + '/' +CAST(SUBSTRING(date_sent,4,2) as int) + '/' +CAST(SUBSTRING(DATE_SENT,7,4) as int) From MyTable It is not working, anybody can give me some advise! thanks!
I'm facing a small issue with date conversions. It would have been great if someone could help me out. I have a field in my database (SQL Server 2000) called SavDateTime of type varchar(50). I store dates in this field in the format "dd/MM/yy hh:mms". A sample date would be "23/10/2007 10:15:30 AM". Now I need to have an order by for this field, say like,
select * from sample order by SavDateTime desc
When I execute this query I get an error saying "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.". I tried using the convert method also like CONVERT(DATETIME,SavDateTime,103), but the problem still exists. It would have been helpful if you could provide me with a solution to this problem.
SELECT DSNew, DTTM, RQDT FROM dbo.Feb INNER JOIN DMSEFL ON ACTR = DSNew where cast(DSNew as varchar(20)) = cast(ACTR As varchar(20)) If I run the above query I get zero recs back.
If I substitute a Value then I get the desired results (ie. where DSNew = '93235500') or if I enter (ACTR = '93235500') or if I put (where DSNew = '93235500' AND ACTR = '93235500')
Can anyone suggest a reason why this is happening. I know the records exist on both tables I ran the query in Acess and got the desired resutls.
I have a textbox that is receiving a date in the format mm/dd/yyyy. The field in the database is VarChar size 10. I purposely don't want to use the DateTime data type for various reasons. When I extract the text from that textbox: Example:4/11/2005 I do my INSERT. When I look in the database at that field, it shows up like:April 11, 2005 12 The database's field is VarChar! How/why is it doing automatic DateTime formatting?
Below is my query.Its working great if i remove ,Cast(C.ClassTime as time) as StartDate.But when i use this i get an error as The conversion of a varchar data type to a datetime data type resulted in an out-of-range value My ClassName is a varchar.Whose definition i cant change to DateTime now.But i want to cast it to DateTime.
Code: Select C.ClassID as Appointment_Id,C.ClassName as Appoitment_Descr,Cast(C.ClassTime as time) as StartDate,C.EndClassTime as EndDate, 'Class' as Type From Dojo D inner join DojoClass C on D.SchoolID = C.DojoSchoolID Where D.SchoolID = @DojoID and C.Days like'%' + @Days + '%' Union Select E.DojoEventID as Appointment_Id,E.EventName as Appoitment_Descr , E.EventStartDate as StartDate , E.EventEndDate as EndDate,'Event' as Type From Dojo D inner join DojoEvent E on E.DojoID = D.SchoolID Where D.SchoolID = @DojoID and @Date Between E.EventStartDate and E.EventEndDate