i got a few questions regarding the SQL server 2005. our company just set-up a replication server so that the reports where creating will be separated from the main server which sap clients are connected.
i have encountered several problems, i have a sample table here
DOCNUM, CARCODE, COMMENTS
--------------------------------------------------------------------
123456 TEST 02.19.07 TEST#123456
ETC.. ETC.. 01.31.07 WR55555555
the problem is, when i convert the remarks to a date, i get what i want but, i cannot filter it once converted in a subquery?
my sample query goes like this
select * from
(select docnum, cardcode,
CONVERT(DATETIME,(CAST(substring(ltrim(table.Comments),1,8) AS DATETIME)), 101)
from table where isdate(substring(ltrim(table.Comments),1,8)) = 1 and table.Comments is not null
)
as a
where a Between '01.01.08' and '04.24.08'
and this also dont work
select docnum, cardcode,
CONVERT(DATETIME,(CAST(substring(ltrim(table.Comments),1,8) AS DATETIME)), 101)
from table where isdate(substring(ltrim(table.Comments),1,8)) = 1 and table.Comments is not null
WHERE
CONVERT(DATETIME,(CAST(substring(ltrim(table.Comments),1,8) AS DATETIME)), 101)
Between '01.01.08' and '04.24.08'
i always get the ff error msg:
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string.
i dont have a problem when were using sql 2000 before, but when we upgraded to sql 2005 its a headache..
please i need your advice. btw the comments column is of nvarchar type and the first 8 characters are ALWAYS of the date format (mm.dd.yy) and does it have a factor on the collation settings? the main server uses the SQL_Latin1_General_CP850_CI_AS while the replicated server uses SQL_Latin1_General_CP1_CI_AS
thanks in advance guys, hope you could help me out..
I am inserting date and time data into a SQL Server 2012 Express table from an application. The application is providing the date and time as a string data type. Is there a TSQL way to convert the date and time string to an SQL datetime date type? I want to do the conversion, because SQL displays an error due to the
My date and time string from the application looks like : 3/11/2014 12:57:57 PM
HiWhen we installed SqlServer2000 we left the default collation name(Sql_Latin1_General_CPI_CI_AS).The user defined databases we created afterwards were defined with adifferent collation name in order to be able to accept the character setwe use, Hebrew.We are looking into switching DTSs that we use to copy data from ourmain system , that uses an Ingres database, into OSQL scripts. Althoughthe DTSs successfully copy the Hebrew letters when I copy data with OSQLit comes over as jibberish.After looking into the matter I came to the conclusion that while DTSrefers to specific databases and uses the destination database'scollation name , OSQL refers to the remote server and destination serverand therefore uses the collation name of the server and not of thedatabase. In order for it to successfully copy the Hebrew I need tochange the default collation name of the installation.Is "rebuild master" the way to do such a thing ? (this is a productionserver so we are wary of doing a "rebuild master")Has anyone else run into similar problems when transfering data betweenservers using OSQL ?ThanksDavid Greenberg
I've restored a SQL Server 2000 database with a Latin1_General_BIN collation from a .dmp file to a SQL Server 2005 server with a default collation of SQL_Latin1_General_CP1_CI_AS. When I try to change the database collation I get hundreds of the following error:
The object 'CK_PM10200_GLPOSTD_00AF8CF' is dependent on database collation. So, in this case, is it even possible to change the collation if there are objects in the database that are dependent on it?
There is a citydate field with string data type in SQL 2K,2004-04-04 20-45-08. I'd like to convert it to a datetime data typewhich should be 12/07/2004 1:34:30PM.Please help.*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
hi , i have a problem i have an textarea that i want to convert to DateTime format (dd/MM/yyyy) . the data in the textarea is (dd/MM/yyyy for example 21/12/2005). i need it to add this data in sql server , in smalldatetime formation colum . plz help.
Hi, Ive imported a data set into SQL. Now on redefining a text field to datetime, most dates that are filled come through okay.
The issue is that there are some empty fields which I'd like for it to stay empty after conversion. Now what happens is that the empty field becomes '01/01/1900' - which is throwing off our queries as we need it to be compared to other date fields.
Is there a way to keep it empty even after the datatype is changed to datetime? Thanks a bunch!
SELECT SUM(CASE WHEN [PO Date] BETWEEN CONVERT(Datetime, @FY + '/04/01') AND CONVERT(Datetime, @FY -1 + '/03/31') THEN Quantity ELSE 0 END) AS Expr1, [Item No_] FROM table A
I am trying to insert data from a web form to a SQL Database. I am receiving the following error: {"String was not recognized as a valid Boolean."} I am also receiving a similar error for text boxes that have dates. Below is the code that I am using: <asp:SqlDataSource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:ConnMktProjReq %>" selectcommand="SELECT LoanRepName,Branch,CurrentDate,ReqDueDate,ProofByEmail,ProofByEmail,FaxNumber,ProjectExplanation,PrintQuantity,PDFDisc,PDFEmail,LoanRepEmail FROM MktProjReq" insertcommand="INSERT INTO MktProjReq(LoanRepName, Branch, CurrentDate, ReqDueDate, ProofByEmail, ProofByEmail, FaxNumber, ProjectExplanation, PrintQuantity, PDFDisc, PDFEmail, LoanRepEmail) VALUES (@RepName, @BranchName, @Date, @DueDate, @ByEmail, @ByFax, @Fax, @ProjExp, @PrintQty, @Disc, @Email, @RepEmail)"> <InsertParameters> <asp:FormParameter Name="RepName" FormField="LoanRepNameBox"/> <asp:FormParameter Name="BranchName" FormField="BranchList"/> <asp:FormParameter Name="Date" FormField="CurrentDateBox" Type="DateTime"/> <asp:FormParameter Name="DueDate" FormField="ReqDueDateBox" Type="DateTime"/> <asp:FormParameter Name="ByEmail" FormField="ProofByEmailCheckbox" Type="boolean"/> <asp:FormParameter Name="ByFax" FormField="ProofByFaxCheckbox" Type="boolean"/> <asp:FormParameter Name="Fax" FormField="FaxNumberBox"/> <asp:FormParameter Name="ProjExp" FormField="ProjectExplanationBox"/> <asp:FormParameter Name="PrintQty" FormField="PrintQuantityBox"/> <asp:FormParameter Name="Disc" FormField="PDFByDiscCheckbox" Type="boolean"/><asp:FormParameter Name="Email" FormField="PDFByFaxCheckbox" Type="boolean"/> <asp:FormParameter Name="RepEmail" FormField="LoanRepEmailBox"/> </InsertParameters> </asp:SqlDataSource>protected void Button1_Click(object sender, EventArgs e) { SqlDataSource1.Insert(); } I have been searching forums for parsing data, but I haven't found anything that works. Can anyone provide guidance. Thank you, Paul
Hi,I am getting this error: String was not recognized as a valid DateTime.I'm trying to insert data into a table from a gridview, where two of the dates can be empty strings.I have set 'allow null' in the SQL Server table for the two dates, added the culture in the web.config file, and even tried converting the values to DBNull.None of which have worked, and I am still getting the error.This is the code I am using: if (e.CommandName == "EmptyInsert") { if (Page.IsValid == true) { TextBox txtVisitDateIns = GridView2.Controls[0].Controls[0].FindControl("txtVisitDateIns") as TextBox; TextBox txtNextVisitDateIns = GridView2.Controls[0].Controls[0].FindControl("txtNextVisitDateIns") as TextBox; TextBox txtVisitedByIns = GridView2.Controls[0].Controls[0].FindControl("txtVisitedByIns") as TextBox; DropDownList ddlPriorityIns = GridView2.Controls[0].Controls[0].FindControl("ddlPriorityIns") as DropDownList; TextBox txtMailshotDateIns = GridView2.Controls[0].Controls[0].FindControl("txtMailshotDateIns") as TextBox;
if (txtNextVisitDateIns.Text == "") txtNextVisitDateIns.Text = DBNull.Value.ToString(); if (txtMailshotDateIns.Text == "") txtMailshotDateIns.Text = DBNull.Value.ToString();
SPVisitsBLL visits = new SPVisitsBLL(); visits.AddVisit(Convert.ToInt32(GridView1.SelectedValue.ToString()), Convert.ToDateTime(txtVisitDateIns.Text.ToString()), Convert.ToDateTime(txtNextVisitDateIns.Text.ToString()), txtVisitedByIns.Text.ToString(), Convert.ToInt32(ddlPriorityIns.SelectedValue.ToString()), Convert.ToDateTime(txtMailshotDateIns.Text.ToString())); GridView2.DataBind(); } } I haven't checked txtVisitDateIns to see if it is an empty string as this date is required.Can anyone help?Thanks
I have a dropdown list thats boudn to a SqlDataSource. The DataSource looks like this: <asp:SqlDataSource ID="dsProgramList" runat="server" ConnectionString="<%$ ConnectionStrings:csData %>" SelectCommand="SELECT DISTINCT [Program_Name] +','+ [Begin_Date] AS NAMEandDATE, [Course_ID], [LOC] FROM [ThisTable] WHERE ([LOC] = @LOC)"> <SelectParameters>
Where the dropdownlists text = NAMEandDATE and its value = Course_ID When I select the LOC from the LOCdropdownlist, the dropdownlist in question updates, and an error "Erro converting datetime from character string" happens? Any suggestions?
Dim CityTown As String = Ctype(Request.Querystring("CityTown"), String) Dim Suburb As String = Ctype(Request.Querystring("Suburb"), String) Dim SuburbValue As String = Ctype(Request.Querystring("Suburb"), String) Dim Rooms As String = Ctype(Request.Querystring("Rooms"), String) Dim Rent As String = Ctype(Request.Querystring("Rent"), String)
Dim DateToday = DateTime.Now Dim mySQL AS String If suburbValue = "- All -" Then mySQL = "SELECT propListID, propListExpires, propBuildType, propRoomNumber, propRentPerWeek, propDescription, propCityTown, propSuburb FROM tblPropertyList WHERE [propCityTown]='" & CityTown & "' AND [propRentPerWeek]<= '" & Rent & "' AND [propRoomNumber]='" & Rooms & "'AND [propListExpires] >='" & DateToday & "' "
However I am having trouble getting the Date to work as part of my SQL String. I keep getting the following error:
Syntax error converting datetime from character string. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Syntax error converting datetime from character string.
Source Error:
Line 30: MyDA = New SqlDataAdapter (mySQL, myConn) Line 31: myDS = New DataSet() Line 32: myDA.Fill(MyDS) Line 33: Line 34: dlPropertyListing.Datasource = MyDS.Tables(0)
Can anybody point me to a list of all valid string formats for passing in datetime variables into SQL server. Ideally I just want to put in a date and not bother with a time
I am passing a string to my stored procedure call where I convert it to a DateTime. I have pasted the relevant code below. My trouble is that prior to execution of the stored procedure an error is thrown "String was not recognized as a valid DateTime". The error does not get thrown when I pass it a date, it only throws it when no date is provided. The page I am using is a form to do a search. The search can allow a date to be entered or left out. How do I catch an empty value in the c# for an invalid datetime and still send the variable to the stored procedure. //////////////////////////// C# Code /////////////////////////////////// Passing the Date to a stored Procedure SqlParameter bdpDateFrom = new SqlParameter("@datefrom", SqlDbType.DateTime);bdpDateFrom.Value = Convert.ToDateTime(thisbdpDateFrom);myCommand.Parameters.Add(bdpDateFrom); ///////////////////////// Stored Procedure Code //////////////////////////////////@datefrom datetimeIF ((@datefrom IS NOT NULL) AND (@datefrom <>' '))BEGIN SET @whereclause = @whereclause + ' AND T1.c330101invoicedate_dt >= ''' + convert(varchar,@datefrom) + ''''END Thank you!
So, i am building a string using datepart and then adding the time at the end. The 120 after the final comma is to define the style (as i am sure you will all know anyway).
When i run this i get the following error:
Msg 245, Level 16, State 1, Line 35 Syntax error converting the varchar value ' 16:30:00' to a column of data type int.
If i take out the colons it runs but brings back the wrong date, the whole date seems to be dependant on the time part at the end.
I am sure this is a really simple problem and i am sorry if i am wasting you time but its late and i just cant see it. Any help would be fantastic.
Can anyone tell me what this error message means and how I can correct it on my statement: Code:
Server: Msg 241, Level 16, State 1, Line 1Syntax error converting datetime from character string.
Here's my query statement: Code:
SELECT animalid AS "Animal ID", name AS "Name", categoryid AS "Category ID", DATENAME(MONTH, dateBorn) + ' ' + DATENAME(DAY, dateBorn) + ', ' + DATENAME(YEAR, dateBorn) AS "Date of Birth"FROM animalWHERE categoryid = 'Cat' AND dateBorn = 'May%'
I know it has something to do with: dateBorn = 'May%' because when I took out Quote: AND dateBorn = 'May%' I get results, but I need to narrow it down to list the cats born in May.
I am trying to select all members from a SQL db who have a renewal date btw to dates inputted into two text fields, but I am now getting the error above. This is where the problem is coming in...
If strStartDate <> "" and strEndDate <> "" Then If bParam = True Then StrSQL = strSQL & " AND " Else StrSQL = strSQL & " WHERE deleted=0 AND " End If strSQL = strSQL & "renewal_due BETWEEN '%" & Replace(strStartDate,"'","''") & "%' AND '%" & Replace(strEndDate,"'","''") & "%' " End If
New to the forums here. I'm not a beginner with SQL, but nor am I a SQL developer - network engineer who knows some scripting and the fundamentals of DB design/administration. There's the background.
I have a database of client information where a date is keyed in and stored as text. Because this is entered by end-users, the way it's entered varies - 1/1/2001, 01/01/2001, etc. Most use "1/1/2001" (note the date is not the same for each record)
I have 4,000 records to update and I need to try to convert the text string to the correct date - changing 1/1/2005 to the same date in proper date/time format. My database uses datetime as an integer calculating the number of days from 12/30/1800. Today's date would be 75508. Time is separated into different fields.
I can do the work to update the text to a single format to make the conversion easier, but I am having trouble locating the proper way to write a convert function to do this. I've searched online (which is how I came here) and have searched the forums without luck.
set @date = (select dateadd(day,0,getdate())) set @day = (select datepart(day,@date)) set @month = (select datepart(month,@date)) set @year = (select datepart(year,@date)) set @tarih = (select '''' + @year + '-' + @month + '-' + @day + ' 00:00:00.000''' )
if @month < 10 begin set @month = '0' + @month end if @day < 10 begin set @day = '0' + @day end -------------IT GIVES ERROR HERE set @dateS = (select '''' + @year + '-' + @month + '-' + @day + ' 00:00:00.000''' )
--- well , when i try this > set @date (which is datetime format ) = '2008-03-22 00:00:00.000' it works(manually), but i cant dynamically bind my string to datetime formatted field.
then i tried, set @dates = (select '''' + @year + @month + @day + '''' ) set @date = (select convert(datetime,@dates)
Hello, i try to work a my Pocket PC project. I have a question about SQL.
How to write a sql select dataset from table with a give string date but the column is datetime? I don't know how to convert the date string to datetime.Also the time part in the datetime coulmn have some value in it, how to get over that?
and how to make sure both format is correct? because as i check the msdn, there are many different format in datetime.
For example
using date string XX-XX-XXXX to select dataset in the following table
table with following column DateTimeStamp XX-XX-XXXX yy:yy:yy:yyyy
When I go to Report > Report Parameters... in VS, I create date parameters and specify the type as datetime. I then add the parameters to my SQL statement. I then go back to look at the parameters and they have changed to string. This happens every time I make a modification to the SQL statement. Is this a bug, or am I missing a step? I thought someone would have asked this before, but I can't find a post for it in this forum.
Dear Friends, I have a doubt relation when converting a field€¦ I €˜m converting a string to datetime inside a SQL command in an OLE DB Source using this: convert(datetime,[Maturity],103) As MaturityDate It€™s better to use inside the OLE DB Source or is better to convert it with data conversion transformation?? Regards!! Thanks
Being a newbie to SSIS I'm not sure of the most efficient method of converting a DateTime object to a String.
I'm from a C# background where this would be easy using DateTime.ToString("YYYYMMdd"). I want to use the date in a file name so don't require most of the parts.
I'm sure I could do this using a script task to produce a file name for each row of data in my table and add that filename to the dataset but it seem like overkill to do something that should be simple. Also as I'm supposed to be getting to grips with SSIS I shouldn't keep running back to what I know.
My current approach is to derive a column and build up an expression to convert the date into a string. The only problem being that it doesn't work. The expression I'm working with is: (DT_WSTR, 50)([OrgName] ) + "_" + (DT_WSTR, 50)( [PayrollName] ) + (DT_WSTR, 4)(YEAR( [ProcessedDate] )) + (DT_WSTR, 2)(MONTH( [ProcessedDate] )) + (DT_WSTR, 2)(DAY( [ProcessedDate] )) ".txt"