hi i want to insert the varchar value inter column, how can i convert the values and insert in to the record if i give direct column name i am getting a message
insert into EMP(id)
SELECT name from STU
i am getting a message like this
Syntax error converting the varchar value '200.00' to a column of data type int.
declare @found int; set @found = 'select sid from StickyContent where StickyId='+0+' and UserId='+171 exec (@found) delete from StickyContent where sid = @found
I need to pass this statement from my UI i.e in a single query. I am getting this error.
"Conversion failed when converting the varchar value 'select sid from StickyContent where StickyId=' to data type int. "
I have a table of zip codes, some with Canadian zips. I'd like to takea zip code and search for nearby zips. For example:Dim theZip As Integer = textbox1.text....Parameter.Add(@ziplow, SqlDbType.Int, 5).Value = (theZip - 10)....Parameter.Add(@ziphigh, SqlDbType.Int, 5).Value = (theZip + 10)SELECT * from ZIPCODES where Cast(zip_code as Integer) BETWEEN @lowzipAND @highzipProblem is the letters in the Canadian records cannot be cast asintegers for this process. I get this error:Syntax error converting the varchar value '53151 1' to a column of datatype int.Is there a SQL query that can exclude if no cast can be made to anInteger?Thanks!Anton
How do we convert both of them into a single SQL DateTime field such as "2015-07-16 01:23:45.000" so that it can be used in a join restricting to a date time in a different SQL File that properly has the DateTime in it?
This works well for converting the transDate Part in the select statement:
  dbo.IntegerToDate(at.transDate) as transDate
  * That returns: "2015-07-16 00:00:00.000"
* The resulting data must work directly in a Microsoft SQL Server Management Studio Query using either using the "on" statement or part of the "where" clause. In other words, NOT as a stored procedure!
Also must be able to be used as a date difference calculation when comparing the 2 files Within say + or - 5 seconds.
In my database I have a table called "users" with a varchar-field that holds categori-id's commaseparated, collected from my other table "category". I do this to control access for my users, some users are only allowed access to some categories. I would like to run a statement sort of like this:select categoryname from category where catid in (select categories from user where userid = 12)Naturally, because catid and the field categories have different datatypes I get the error "Syntax error converting the varchar value '340, 344, 356' to a column of data type int."
Is there any way I can bypass this keeping the commaseparated values and without making a new normalized table instead?
(same question is also posted at sql-server-performance.com forums)
tbl_Projects ------------------------- ProjID | Description ------------------------- 1 | First 2 | Second 3 | Third
I want to write a SELECT statement that will output in this format: 1 - First 2 - Second etc...
I've tried these two statements:
SELECT (ProjID + ' - ' + Description) AS Projects FROM tbl_Projects //Error: Conversion failed when converting the varchar value 'First' to data type int.
and
SELECT CONCAT(ProjID, CONCAT(' - ', Description)) AS Projects FROM tbl_Projects //Error: The data types int and varchar are incompatible in the concat operator.
Is there any way to concatenate an int value with a varchar value?
Hi All I'm getting an error that says that this can't be converted to an integer. Here is the line that gets the error. dt = ((DataView)(EventDataSource1.Select(dssa))).ToTable() I have also tried. dt = (DataView)(EventDataSource1.Select(dssa); I am programming in VB here is teh rest of my code. Dim EventDataSource1 As New SqlDataSource()EventDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToStringDim dssa As New DataSourceSelectArguments()Dim EventID As String = ""Dim DataView = ""Dim dt As New Data.DataTableDim conn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString())Dim cmd As New Data.SqlClient.SqlCommand("SELECT EventID FROM Event WHERE ([StartDate] = @StartDate)", conn)EventDataSource1.SelectCommand = ("SELECT EventID FROM Event WHERE ([StartDate] = @StartDate)")conn.Open()dt = ((DataView)(EventDataSource1.Select(dssa))).ToTable()EventID = dt.Rows(0)(0).ToString()EventDataSource1.SelectParameters.Add("@StartDate",StartDate)EventID = cmd.ExecuteScalar()
I have the following stored procedure for creating a transaction record and after inserting the record, the transaction id is returned.-----------------------------------------------------DECLARE @TransactionID int <------ INSERT statement (after inserting the record, select the identity ID) ---------> Select @TransactionID = @@Identity RETURN------------------------------------------------------...Dim transactionID As Integerconnection.Open()Dim reader As SqlDataReaderreader = command.ExecuteReader(CommandBehavior.CloseConnection)Dim p3 As New SqlParameter("@TransactionID", SqlDbType.Int)p3.Direction = ParameterDirection.OutputtransactionID = Convert.ToInt16(p3.Value)connection.Close()...I wanna retrieve the transactionID of the newly inserted record so that I can use it in my next step of inserting a new record to another table which has reference to the transactionID as a foreign key. However, I encountered error and suspect that it is due to the conversion of the output to Integer as it worked when I tested using dummy Integers.I tried many different ways of conversion but couldn't resolve the error. Could anyone help?
Hi folks, I'm trying to import data from a text file (UnicodeData.txt) into an SQL table. Some of the fields are unicode values (16 bits) expressed as four hexidecimal digits. I've succeeded in importing the data as character strings, but I have not found a way to convert them into numbers. (They could be stored as int or nchar.) I've tried convert(binary/int/whatever, string); E.g. select convert(int, '0x1111') from import_unicode gives the error Syntax error converting the varchar value '0x1111' to a column of data type int.
I could write code to strip off one character at a time, convert the hex digit to a decimal value, shift left, etc., but I find it hard to believe that's the best way.
Any help is appreciated. Please email answer to lars_huttar@sil.org as I don't read this board.
I have checked the forums but couldnt find exact term. I have written tsql statement but I dont know how to use that in SSIS this is a update statement in oledb command component... I wanna get integer like YYYYMMDD ( 20080325)
Hi, I need help. Understatement of the year right now, too = So... I've created a stored procedure that partially pulls a SQL union query to give me a complete one-line result set of a bunch of data... four separate selects comprise the query. The tables are structured identically to each other, but the values being pulled are specific and distinct. All of the non-date values stored are varchar values in the tables, and yet when I execute the SQL union query, I get the error message: Syntax error converting the varchar value to a column of data type int. I know SQL does implicit conversions, however Im not sure why it's trying to do that with this query, I suppose. it should have been straightforward. Any suggestions? Here is the query logic to look at, in case I'm missing the obvious
exec(' SELECT ACCOUNT, LNAME, FNAME, SEX, DOB, cast(MA_ContentValue as decimal) as MA_ContentValue, cast(MA_DOS as smalldatetime) as MA_DOS,cast(LDL_ContentValue as decimal) as LDL_ContentValue, cast(LDL_DOS as smalldatetime) as LDL_DOS, cast(HgbA1C_ContentValue as decimal)as HgbA1C_ContentValue, HgbA1C_DOS, cast(Creatinine_ContentValue as decimal) as Creatinine_ContentValue, Creatinine_DOS FROM ( SELECT Account, Lname, FName, Sex, DOB,MA_ContentValue, MA_DOS, 0 as LDL_ContentValue, 0 as LDL_DOS, 0 as HgbA1C_ContentValue, 0 as HgbA1C_DOS, 0 as Creatinine_ContentValue, 0 as Creatinine_DOS FROM dbo.vwDiabetic_MicroalbuminTop3 UNION SELECT Account, Lname, FName, Sex, DOB, 0 as MA_ContentValue, 0 as MA_DOS, LDL_ContentValue, LDL_DOS, 0 as HgbA1C_ContentValue, 0 as HgbA1C_DOS, 0 as Creatinine_ContentValue, 0 as Creatinine_DOS FROM dbo.vwDiabetic_LDLTop3 UNION SELECT Account, Lname, FName, Sex, DOB, 0 as MA_ContentValue, 0 as MA_DOS, 0 as LDL_ContentValue, 0 as LDL_DOS, HgbA1C_ContentValue, HgbA1C_DOS, 0 as Creatinine_ContentValue, 0 as Creatinine_DOS FROM dbo.vwDiabetic_HgbA1CTop3 UNION SELECT Account, Lname, FName, Sex, DOB, 0 as MA_ContentValue, 0 as MA_DOS, 0 as LDL_ContentValue, 0 as LDL_DOS, 0 as HgbA1C_ContentValue, 0 as HgbA1C_DOS, Creatinine_ContentValue, Creatinine_DOS FROM dbo.vwDiabetic_CreatinineTop3) tbl1
') Anything else that I can provide for someone to help me? I appreciate any/all feedback!
Hi, I am extracting data from DB2 into SQL server using DTS. We have the data type char(5) in DB2 and int in SQL server. I tried to give the select integer(columname) as columname from tablename in data source. I did parse the query it was Ok but If I tried to execute that giving the following error. Can you give me your answere for this issue.
--------------------------- Package Error --------------------------- Error Source : Microsoft OLE DB Provider for ODBC Drivers
Error Description : [StarQuest][StarSQL ODBC Driver][DB2]THE VALUE OF A CHARACTER STRING ARGUMENT WAS NOT ACCEPTABLE TO THE INTEGER FUNCTION
--------------------------- OK ---------------------------
In a table, I store an integer to represent a day of the week (1 = sunday ) and then in procedures, compare that to datepart(dw, getdate()) to do alternative tasks on certain days.
If I have the number 1, is there a built in function to convert that to sunday or should one just write a function to do just that?
I want to convert a string into an interger so that my parameter can get one value, and have a seperate matrix list the value before the value selected.
My parameter is year. The user picks the year. And i want the crashcounts for the year displayed in the matrix. Then i have another matrix with a dataset similiar. I want this seperate Matrix/Dataset to display the previous year.
SO if the user selects 2004 from the dropdown. 2004 is displayed in the first matrix, and 2003 is displayed in the second matrix. The year attribute is in string format, and i cant change it in the cube. So i was told it could be converted in reporting services. with this
I have imported a text file with various data into sql table. all these values have been imported as nvarchar. I need to convert these into Integer. the format of the values is 10length i.e. 0000000.00. example of data: 0001028.99 - needs to be shown as 1028.99 222.00 - needs to be shown as 222.00 0000190.89 - needs to be shown as 190.89 2708.99 - needs to be shown as 2708.99 00000-50.99 - needs to be shown as -50.99 -109.79 - needs to be shown as -109.70
as you can see some of the values have leading zeros and some don't. i have tried converting from nvarchar to int and i get the error cannot convert nvarchar to int, i believe it may be because the data contains negative values as well as positive values.
Is there a split function or position function which i can use to extract the data? or any other methods which i can use would be really helpful.
In VBA, CLng(Now) will return the integer portion of a date CLng(Now) returns 41928, CDate(41928) then returns 10/16/2014. Is there something equivalent in SQL Server that will allow me to convert an integer value to a date?
In short, how can I convert a 100 year date to Gregorian (any format)?
I am querying DB2 from SSRS. I get an interger back that represents a time like this: HHMMSS (The data type in DB2 is an integer.) I would like to make this representation of the time display a little more friendly. Does anyone have a good idea on how I can change the query or SSRS format to display semi-colons to break up the hours, minutes and seconds? Also, the other issue is that since I don't get leading zeros back....they probably need to be added to this value if the value is not a full 6 characters.
I need to convert a a string column to integer. Before converting, I need to check if it has blank values then convert it to NULL. Someone told me that its easier to convert it to NULL before converting to integer.
this is in form VB Private Sub orderidtxbx_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles orderidtxbx.Click sqlconnection = New SqlConnection("Data Source= xxxx;Initial Catalog = xxxx; user ID = sa; Password = xxxxx;") sqlcommand = New SqlCommand("select Customer.LastName, Customer.FirstName from customer where ticket.ticketid ='" & orderidtxbx.Text & "'", sqlconnection)
error msg The multi-part identifier "ticket.ticketid" could not be bound
query in sql 2005,I need to make store procedure.
SELECT Itinerary.FlightID, Itinerary.Class, Itinerary.Quantity, Ticket.Date, Flight.FlightNo, Flight.AirLine, Flight.DepartureDate, Flight.ArrivalDate, Flight.DepartureTime, Flight.ArrivalTime, Flight.Price, Departure.DepartureLocation, Arrival.ArrivalLocation,GST=convert(int,Itinerary. Quantity*0.06*Flight.Price),PST=convert(int,Itiner ary.Quantity*0.07*Flight.Price),TotalPrice=convert (int,(Itinerary.Quantity*0.06*Flight.Price)+(Itine rary.Quantity*0.07*Flight.Price)+Flight.Price) FROM Flight INNER JOIN Itinerary ON Flight.FlightID = Itinerary.FlightID INNER JOIN Ticket ON Itinerary.TicketID = Ticket.TicketID INNER JOIN Departure ON Flight.DepartureLocationID = Departure.DepartureID INNER JOIN Arrival ON Flight.ArrivalLocationID = Arrival.ArrivalID WHERE (Itinerary.ticketid = '@Itinerary.ticketid')
if i change WHERE (Itinerary.ticketid = 1) it will read the data in the table.
I need to refer that itinerary.ticketid into textbox in form that's why i make like this WHERE (Itinerary.ticketid = '@Itinerary.ticketid') but i don't know what is worng with this.
This error Msg 245, Level 16, State 1, Line 2 Conversion failed when converting the varchar value '@Itinerary.ticketid' to data type int(but my ticketid value already integer not varchar).
I am trying to run this statement Select Calims, ProCode From Inquiry Where ProCode Between 80000 and 89999
ProCode is a varchar but I am still checking a range on it. It seem to work fine but then there is some invalid data entry in this column for example 'abace' or '100i' so I get the error. 1) how I can exclude them out of my query. Someone suggested the following but I dont understand how do achieve that. thanks
" However, there would appear to be different data types. If Value is a character --based type then you may want to limit the search by first extracting numeric values -- with something like ISNUMERIC(Value) = 1 and then converting them to numerics using --the convert function - CONVERT(int, Value) BETWEEN 10000 and 20000."
Hi all iam trying to but a varchar variable into a TEXT var but i get this error "The assignment operator operation cannot take a text data type as an argument"
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 am using a varchar datatype for PIN number to handle zero at start. Now i want to do mathematical calculation to encrypt the PIN so i need to convert that varchar datatype to int so that zero should not be discarted after conversion. i.e. 0123 and 123 must not be treated as same PIN.
Please kindly give me a way out. I am using RSA encryption.
Using SQL 2005. I have a field with dollar amounts but field type is VarChar. Need to convert to number to sum. What's the best way to do this or how can I sum a field type Varchar that has dollar amounts. Thank you, David