invalid data is getting inserted in table in sql server database - sql

I faced a situation and also searched for it in the internet but could not be able to get any solution.
Problem
My sql server table has 15000 records. It has several columns.
Among all the records, the 'Email ID' column of one record is storing value along with an unidentified character at the beginning. (Please refer to picture attached)
What I want
I want to get rid of that character using sql query. I am using sql server 2012 version.
I tried with 'replace()' and 'patindex()'. I even tried 'stuff' function.
But, its not working. Instead, when I am fetching the data using query, it is showing that typical character.
Please help me with some ideas. If I need to do some settings in database or table, I am ready for that.
Thanks.

Related

SQL Server select query output shows as "???????"

I got an email from my senior, to update a table column in SQL server.
In the mail they mentioned the data to update.
But when I copied the below mentioned content and used select query in SQL Server it results in "??????" characters.
Landmark : πš—πšŽπšŠπš› πš”πš˜πš™πšŠπš• πš”πš’πšπšœ πšŒπš˜πš•πš•πšŠπšπšŽ,πš‹πš‘πšŠπš πš›πšŠπšœπš•πšŠ
select 'Landmark : πš—πšŽπšŠπš› πš”πš˜πš™πšŠπš• πš”πš’πšπšœ πšŒπš˜πš•πš•πšŠπšπšŽ,πš‹πš‘πšŠπš πš›πšŠπšœπš•πšŠ'
I tried varbinary, ASCII conversion in SQL server and tried to format the data using word and excel but nothing works for me.
To my knowledge I think the data is in image format.
Please help me with this issue.
Note: I can simply type the content and update, but for my curiosity I want to know how to fix this issue.

Export SQL Server linked server table with 334449 rows

I want to export the data from a table from linked server. The table has over 300,000 rows.
When I run this query:
SELECT *
FROM [LSERVER].[LTechnologies].[Connector].[MASD]
I get an error:
OLE DB provider 'MSDASQL' for linked server 'LSERVER' returned data that does not match expected data length for column '[LSERVER].[LTechnologies].[Connector].[MASD]'. The (maximum) expected data length is 8000, while the returned data length is 8448.
The source is NetSuite linked to MS SQL as ODBC Data Source.
Is there any way to work around this limitation?
Thanks
Is there any way to work around this limitation?
The typical workaround is to use OPENQUERY to send a "passthrough" query to the target system and ask it to perform type conversions to the types that actually work.
Haim, it sounds like a built limitation limiting varchar or nvarchar to 8K characters. I have seen this a couple times but never seen anyone beat it - normally we just exclude the column. However if it's worth the time, you could find the column and do a LEFT([column], 7999) to see if you can at least get most of the data back. Hope it helps.

SQL error message when querying table containing one varbinary (blob) field

We are using Delphi XE3 together with a TSQLDataSet and a TClientDataset to read a table into memory from SQL server 2012.
The table contains various fields, one of them a blob "varbinary(max)" where we store the content from a text file.
My problem is that we get an error message saying "connection is busy with results for another command" when we do a open on the ClientDataset.
The commandtext is a simple "select * from tablename".
This happens only if there are more than one item in the table. It also happens only if there are data in the blob field (<> NULL).
Everything work fine if we add a second varbinary field to the table. The second field does not have to contain any data.
This is driving me crazy, please help.
EDIT: As a workaround we have simply added a "dummy" varbinary field to the table. Because of this strange behavior, we have come to the conclusion that this has to be a bug in the TClientDataset component. Tried to do the same in a older version of delphi (XE2 SP3) with the same result.

Create delimited string from a row in stored procedure with unknown number of elements

Using SQL Server 2000 and Microsoft SQL Server MS is there a way to create a delimited string based upon an unknown number of columns per row?
I'm pulling one row at a time from different tables and am going to store them in a column in another table.
A simple SQL query can't do anything like that. You need to specify the fields you are concatenating.
The only method that I'm aware of is to dynamincally build a query for each table.
I don't recall the structure of MSSQL2000, so I won't try to give an exact example, maybe someone else can. But there -are- system tables that contain table defintions. By parsing the contents of those system tables you can dynamically build the necessary query for each source data table.
TSQLthat writes TSQL, however, can be a bit tricky to debug and maintain :) So be careful how you structure everything...
Dems.
EDIT:
Or just do it in your client application.

MS Access error "ODBC--call failed. Invalid character value for cast specification (#0)"

Does anyone have an idea what this error means or how to solve it? I am using Access 2003 and SQL2005. It comes up when trying to add a record on a particular subform.
[Microsoft][SQL Native Client] Invalid character value for cast specification (#0)
This MS bug report describes the same message, but it is a bug in SQL Server 6.5 that has already been solved.
Solved: Apparently having no PK on the destination table was causing this, it didn't have anything to do with the subform or the query from Access. I wasn't even aware there were tables in this database without PK. Adding PK to the destination table solved it. The strange thing is the same query string that errored when executed via SQL native client, executed through SSMS with no errors. Hope this helps anyone else who has come across that strange message.
Hum, I would check the text box default on the access side. I would also bring up the linked table in design mode, and you want to check the data type that ms-access assumes here. For non supported data types ms-access will generally use a string, and sql server might be wanting something else.
So, check both the Primary key (PK) in main table, and then check the data type used (assumed) in the child table for the foreign key (FK) column. While we are at this, check your expressions used for the child/master link settings in the sub-form control (not the form, not the sub-form, but the sub-form control used in your form that links up these two tables).
Sub forms in access are sensitive if you don’t have a timestamp column in the sql server table. As mentioned check the PK and the FK data types and make sure they match up (just bring up the tables in design mode in ms-access -- you get an error message about the design mode being read only, but just continue on so you can check/view to ensure the data types match up).
So for the child table, you need a PK, a FK, and also a timestamp column (you don’t have to display the TS column in the sub-form, but you need it in the table).
Sub-forms in ms-access are sensitive and often fail if you don’t include a timestamp column in the sql table. (access uses these row version columns to determine if the data been changed).
Is one of your fields in the view calculated/built with the CAST function? In this case, you might not have the right to update/add a value for that field.
Can you execute your view in the MS SQL Studio interface and try to insert a record?
Another cause to this issue is that if you change a table name without alterting the view then the "Dependencies" of that view still remians with the table old name.
Let say I have a table 'A' and a view 'Av' which derives from 'A', and I created a new Table which will be named 'A' and I changed 'A's name to 'A_old' but I didn't executed an ALTER VIEW, so the dependencies of 'Av' still remain on 'A_old' but the view is derives from 'A' and it cuasing this Error in Access when trying to open the view as a linked table
I just spent a day battling this with an Access ADP project that was imported into a new Access 2016 ACCDB file. Initially I figured it was an issue with the application code, but I was getting this keying records directly into the table. Interestingly, the records always got written - it seemed to be the read-back that was triggering the error. Profiling the insert sql and running that from SQL Management Studio worked without any issues.
The table that was causing the problems had a GUID Primary Key. Switching that to an int column resolved the issue.
The SQL database was also littered with a few thousand extended properties which I removed before switching the PK. There was a strong suggestion from the web that these cause problems. The source of that process is documented here: Remove All SQL Extended Properties
I had this problem with Access 2016 trying to update an ODBC linked sQL Server database. Problem was a null value in field used to join the two tables. Eliminating the null value solved the problem
OK I just had this bad experience and it had nothing to do with PK or any of this stuff in my situation. The view that reported this problem in Access was created in SQL Server originally and used a CAST of DATETIME to plain old DATE to get rid of the unneeded time part. Up until today this view had caused 0 issues in Access, but started to generate heartburn just as described above.
So, I generated a Drop/Create script for the MSS view, ran it, relinked the views in Access, and the Access database was happy with the result. All my so-called tables in Access are basically views through links to MSS for reporting. I only have 1 table that actually does changes. Other than that, I do not edit through views in Access.
The message is of course useless as usual but this was my solution in my situation.
Based solely in the message you provided above, it appears that you are trying to set an invalid value to some field or parameter, etc... The message is telling you that it is trying to convert a value into an specific data type but the value is invalid for that data type... makes sense?
Please add more details so we can help you better.