Might get some negative points here but feel the need to post an problem (And self-defined solution) that I could not match to anything on the interweb...
I have a very simple bit of code that returns the queries that my company's SSRS RDL datasets uses to obtain data.
It works nicely when returning all data, but the moment I add a where clause to only return records with specific text within the data set like the parameter I get an error:
Msg 8152, Level 16, State 10 ...
String or binary data would be truncated
The parameter is defined exactly the same as the column I am searching in is (NVARCHAR(MAX)).
I know what that error means ("The error means that you're trying to put a value into a table that is larger than what the column can hold. I.e. you're to insert a varchar(100) into a column that's been defined as varchar(80).") but what stumped me was that the flippen thing only errors out when run the query with the where clause.
I managed to narrow the culprit record down to one having 12351 characters (Using LEN).
The solution that I found was to change the LIKE to an =. Not 100% ideal because I would like the flexibility to search for any text within the column, but I can live with it.
If you are using LIKE operator in following manner:
WHERE myColumn LIKE '%some text%`
which I suspect you do from your description:
to search for any text within the column
Then, you can replace it with WHERE CHARINDEX('some text', myColumn) > 0 and see if it will work.
Related
Used this site https://community.oracle.com/thread/3937159?start=0&tstart=0 to learn how to manually process interactive grids. I got it to work on a small table with 3 columns, but when I tried to get it to work for a bigger table, it keeps throwing this error:
PL/SQL: numeric or value error: character string buffer too small for.
I tried only updating 1 column and converting the datatype to the correct one, and it is not going away.
this message usually means you're trying to store 'AAAA' into a column that only accepts 1, 2 or 3 chars, like varchar2(3).
Make sure your columns have a proper limit size for the data you're processing.
I'm getting the following error(s)
Msg 117, Level 15, State 1, Procedure lp_..._data, Line 153
The object name 'abcDBProd.Intermediate.dbo.upld_data' contains more than the maximum number of prefixes. The maximum is 2.
Msg 117, Level 15, State 1, Procedure lp_..._Tables, Line 520
The object name 'ABCDBPROD.Intermediate.dbo.UPLD_data' contains more than the maximum number of prefixes. The maximum is 2.
If I understand correctly the purpose/meaning of the error that I can't have more then 2 prefixes prior to the table name. In the first statement i'm using the name of the Server itself and in the second case the LinkedServer name. The confusion I've got is that i have many tables on this server/databse and they are all connected the same and none of them are causing this error. but this one is.
What do I do? Is it a permission issue or security issue? I'm not sure where to look.
Does it matter if the command calling the table, truncates, inserts or updates the data? Are there restrictions like I can't truncate but I can insert? Why does it work in some cases but not in others?
Linked tables are not allowed in some contexts, such as DROP TABLE and INSERT INTO. If you use a name that includes the server name, then you will get this error.
For instance, this is not allowed:
drop table abcDBProd.Intermediate.dbo.upld_data;
You may be able to work around this with openquery().
I have a SQL table with a geography column. When I look at one of the rows the geography shows as a long hex string: 0xE6100....C0.
I want to write a query that finds all other rows in my database that have this same value. How can I do this?
I tried adding WHERE location = '0xE6100....C0' with and without quotes but I get an error:
Invalid operator for data type. Operator equals equal to, type equals geography.
Note: I'm just doing this query in an ad-hoc fashion I'm not really looking for a optimal solution or a way to parameterize this in any way. I just have a row that I'd like to find related values.
Looks like you need to use .STEquals
Check the documentation here
I'm having a table (let's call her t) that contains the fields id(int) and XmlField(xml).
I try to add multiple node in one query but no matter what I tried I keep getting errors.
The query is:
update t
set XmlField.modify('insert <f1>value here</f1><f2>value there</f2> into (/xmldoc)')
and I getting the error:
XQuery [t.XmlField.modify()]: Syntax error near '', expected 'as', 'into', 'before' or 'after'.
When I trying to add only one xml node it's working (example):
update t set XmlField.modify('insert <f1>value here</f1> into (/xmldoc)')
it's also working when I try to add nested nodes like this:
update t set XmlField.modify('insert <f><f1>value here</f1><f2>value there</f2></f> into (/xmldoc)')
Is there any way to make it happen?
The SQL Server documentation does say pretty clearly that the insert statement can handle multiple nodes. So my guess is that your problem is just a syntax error. (The Microsoft syntax varies slightly from that defined in the XQuery Update Facility spec, but it's recognizably similar.)
I'd try making the elements f1 and f2 into a sequence and wrapping them in parentheses (the spec requires an ExprSingle here, which means no top-level commas are allowed):
update t
set XmlField.modify(
'insert (<f1>value here</f1>, <f2>value there</f2>) into (/xmldoc)')
(Not tested against SQL Server.)
I'm trying to replace a Keyword Analyser based Lucene.NET index with an SQL Server 2008 R2 based one.
I have a table that contains custom indexed fields that I need to query upon. The value of the index column (see below) is a combination of name/ value pairs of the custom index fields from a series of .NET types - the actual values are pulled from attributes at run time, because the structure is unknown.
I need to be able to search for set name and value pairs, using ANDs and ORs and return the rows where the query matches.
Id Index
====================================================================
1 [Descriptor.Type]=[5][Descriptor.Url]=[/]
2 [Descriptor.Type]=[23][Descriptor.Url]=[/test]
3 [Descriptor.Type]=[25][Descriptor.Alternative]=[hello]
4 [Descriptor.Type]=[26][Descriptor.Alternative]=[hello][Descriptor.FriendlyName]=[this is a test]
A simple query look like this:
select * from Indices where contains ([Index], '[Descriptor.Url]=[/]');
That query will results in the following error:
Msg 7630, Level 15, State 2, Line 1
Syntax error near '[' in the full-text search condition '[Descriptor.Url]=[/]'.
So with that in mind, I altered the data in the Index column to use | instead of [ and ]:
select * from Indices where contains ([Index], '|Descriptor.Url|=|/|');
Now, while that query is now valid, when I run it all rows containing Descriptor.Url and starting with / are returned, instead of the records (exactly one in this case) that exactly matches.
My question is, how can I escape the query to account for the [ and ] and ensure that just the exact matching row is returned?
A more complex query looks a little like this:
select * from Indices where contains ([Index], '[Descriptor.Type]=[12] AND ([Descriptor.Url]=[/] OR [Descriptor.Url]=[/test])');
Thanks,
Kieron
Your main issue is in using a SQL wordbreaker, and the CONTAINS syntax. By default, SQL wordbreakers eliminates punctuation, and normalizes numbers, dates, urls, email addresses, and the like. It also lowercases everything, and stems words.
So, for your input string:
[Descriptor.Type]=[5][Descriptor.Url]=[/]
You would have the following tokens added to the index (along with their positions)
descriptor type nn5 5 descriptor url
(Note: the nn5 is a way to simplify quering numbers and dates given in different formats, the original number is also indexed at the same position)
So, as you can see, the punctutation is not even stored in the full text index, and thus, there is no way to query it using the CONTAINS statement.
So your statement:
select * from Indices where contains ([Index], '|Descriptor.Url|=|/|');
Would actually be normalized down to "descriptor url" by the query generator before submitting it to the full text index, thus the hits on all the entries that have "descriptor" next to "url", excluding punctuation.
What you need is the LIKE statement.
Using "|" as your delimiter causes the contains query to think of OR. Which is why you are getting unexpected results. You should be able to escape the bracket like so:
SELECT * FROM Indices WHERE
contains ([Index], '[[]Descriptor.Type]=[[]12]')