I've got a full text catalogue setup. It has a unique key count of 117 with 19 items. The table has 19 rows only.
The table has an NVARCHAR(50) field called ClientGuid. It's a guid with some weird text at the end.
eg..
8b6ef4a504dd1a57f079180e7f6eb4a0(-)
8b6ef4a504dd1a57f079180e7f6eb4a0(OK)
(and no, i didn't defined that text field data - we're sourcing it from a 3rd party API.
anways, this is my sql and the query i run against it. When i run the query, i get ZERO results back :(
ALTER FUNCTION [dbo].[Foo_HiJonSkeet]
(
#ClientGuid NVARCHAR(50)
)
RETURNS TABLE
AS
RETURN
(
SELECT KEY_TBL.[Key] as LogEntryId,
KEY_TBL.RANK as Relevance
FROM CONTAINSTABLE(LogEntries, ClientGuid, #ClientGuid) AS KEY_TBL
)
SELECT * FROM Foo_HiJonSkeet('8b')
Any suggestions?
Server is Sql Server 2008.
You can try the following construction:
SELECT * FROM Foo_HiJonSkeet('"8b*"')
adding the double quotes and an asterisk after the original search term. It should work.
But in the case if all the searches will be similar to the example you've posted above, I advise you to use LIKE statement instead of using full text search.
Related
Trying to do a simple Snowflake query as such:
SELECT *
FROM TABLE
WHERE NAME_COLUMN LIKE '%ABC%'
Yet I'm getting the following error.
SQL compilation error: error line 17 at position 12 Function LIKE does not support collation: en-ci-rtrim.
What is the work around here? I don't have the ability to alter the underlying table or the collation attributes.
You can re-colate in real time:
create or replace temp table collation_demo (
uncollated_phrase varchar,
stack_phrase varchar collate 'en-ci-rtrim'
);
insert into collation_demo (uncollated_phrase, stack_phrase)
values ('pinata', 'pirata');
select *
from collation_demo
where collate(stack_phrase, 'en') like '%pi%'
order by stack_phrase
If you remove the collate() call around stack_phrase you'll get the same error. But with it, the query works as expected.
Another workaround is to use a different string comparing function that supports the existing collation. For example, contains():
select *
from collation_demo
where contains(stack_phrase, 'PI');
Works!
I have set up and enabled semantic search successfully by following this tutorial by Microsoft in SQL Server 2017 Development Edition. The semantic search is enabled on a table nvarchar(max) field which retains English plain text to search them semantically. The table has 900+ rows but when I run the following SQL statement I do not receive more than 10 rows! Why am I seeing this behavior and what should I do to get more rows in the result of the statement?
declare #idToCompare int = 1044
SELECT TOP(50) KEY_TBL.matched_document_key AS MatchId , score
FROM SEMANTICSIMILARITYTABLE
(
MySemanticTable,
ContentToSearch,
#idToCompare
) AS KEY_TBL
ORDER BY KEY_TBL.score DESC
Turns out that this is an old issue that has never been addressed. This feature of SQL Server does not seem to worth utilizing unless there is a solution for that. Not sure why Microsoft introduced this feature!
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d9bdd8d5-dec4-4076-bcb8-692f1d509c74/semanticsimilaritytable-sql2012-1102100-why-pull-max-of-only-10-results?forum=sqldatabaseengine
I am generating XML from 60 tables, and storing this xml in a table.
Table Name : Final_XML_Table
PK FK XML_Content (type xml)
1 1 "XML that I am generating from 60 tables"
When I am running below query , it gives memory exception :
Select * from Final_XML_Table
Things I have tried :
1. Results to text : I am getting only few lines from XML as text in output window
2. Results to file : I am getting only few lines from XML in file.
Please suggest, and also if there is any change , will I have to do this on server's SQL server as well while deployment.
I have also set XML_Data to unlimited :
This is not an answer, but to much for a comment...
The fact, that you are able to store the XML, shows clearly, that the XML is not to big for the database.
The fact that you get an out-of-memory exception with Select * from Final_XML_Table shows clearly, that SSMS has a problem on reading/displaying your XML.
You might try to check the length like here:
DECLARE #tbl TABLE (x XML);
INSERT INTO #tbl VALUES('<root><test>blah</test><test /><test2><x/></test2></root>');
SELECT * FROM #tbl; --This does not work for you
SELECT DATALENGTH(x) FROM #tbl; --This returns just "82" in this case
Might be, that due to a logical error in your XML's creation (a wrong join?) the XML contains multiple/repeated elements. You might try a query like this to get a count of nodes in order to check if this number is realistic:
SELECT x.value('count(//*)','int') FROM #tbl
For the exampe above this returns "5"
You might do the same with your original XML.
With a query like the following you can retrieve all node names of the first level, the second level and so on. You can check if this looks okay:
SELECT firstLevel.value('local-name(.)','varchar(max)') AS l1_node
,SecondLevel.value('local-name(.)','varchar(max)') AS l2_node
--add more
FROM #tbl
OUTER APPLY x.nodes('/*') AS A(firstLevel)
OUTER APPLY A.firstLevel.nodes('*') AS B(SecondLevel)
--add more
And - of course - you might open the ResourceMonitor to look at the actual usage of memory...
Come back with more details...
That error isn't a SQL Server error, it's from SSMS. It means that SSMS has run out of memory.
SSMS is only a 32bit application, so can only address 2GB of RAM. If it tries to address more than that, the error will occur. if you've had SSMS open and returned some very large datasets, that RAM is going to get used up.
In all honesty, if you're running a query like SELECT * FROM Final_XML_Table then I would hazard a guess that the dataset is huge. Add a WHERE clause, or don't return the dataset on screen. if you really need to view the data (all of it), export it to something else. But I very much doubt you need to look at every row, if you're returning around 2GB of data.
I want to send the date range and employee ids from SSRS to Oracle package. Does anyone knows how to do it? Even if i try to declare an oracle package with three in parameters from_date, to_date and employee_id it works fine with one employee id. But fails if i select multiple employees in SSRS web interface saying wrong number of parameters. Does anyone know how to handle this?
Normally with SQL and SSRS you would do something like
Select * From Table where Table.Field in #Param
Oracle is different of course and depends on the Connection Type you are using.
ODBC connection you would use something like:
Select * From Table where Table.Field = ?
Order of the parameters is important here so be careful.
OLEDB connection you would use something like:
Select * From Table where Table.Field = :Param
However, none of the above work with multi selecting of the Parameters. You could do this:
=”Select * From Table where Table.Field in (‘” + Join(Parameters!parameter.Value,”‘, ‘”) + “‘)”
or
=”Select * From Table where Table.Field in(” + Join(Parameters!parameter.Value,”, “) + “)” if the values or your field is only numeric.
Here are a couple of good articles that you can look at. It has a better explanation than I can give personally without more information; Details of your Oracle Environment, Connection Type, etc.
Quick Reference:
Be sure your Oracle version is 9 or greater, none of this works on
versions 8 or older.
When using parameters with Oracle, use a : instead of an # sign –
:param instead of #param.
Add an ‘ALL’ option to your datasets that supply values for
multivalued drop down parameters.
Check for the ALL in your where clause by using “where ( field1 in (
:prmField1 ) or ‘ALL’ in ( :prmField1 ) )” syntax.
You can execute your query from the dataset window, but can only
supply 1 value. However that value can be ‘ALL’.
Educate your users on ‘ALL’ versus ‘(select all)’ .
Another good article about Multiple Parameters in SSRS with Oracle: Davos Collective Which is referenced in the top portion.
Hope this helps!
I keep getting 'Invalid object name 'SEMANTICSIMILARITYTABLE' when I try to find documents similar based off their body (I am using SQL Server 2012).
Here's the query:
declare #ID int
select top 1
#ID = ID
from dbo.Documents with (nolock)
select *
from SEMANTICSIMILARITYTABLE
(
dbo.Documents,
Body,
#ID
)
If I run the following, everything returns 1 (indicating that everything is set up correctly as far as the full text search and indexes, I believe):
SELECT DATABASEPROPERTYEX('MyDatabase', 'IsFullTextEnabled') [Database_Supported]
GO
SELECT OBJECTPROPERTYEX(OBJECT_ID('dbo.Documents'), 'TableFullTextSemanticExtraction') [Table_Supported]
GO
SELECT COLUMNPROPERTY(OBJECT_ID('dbo.Documents'), 'Body', 'StatisticalSemantics') [Column_Search_Supported]
GO
SELECT * FROM sys.fulltext_index_columns WHERE object_id = OBJECT_ID('dbo.Documents')
GO
Any ideas or tips?
EDIT
Just some more info on the table (dbo.Documents):
ID is the identity column (which also serves as the primary key)
The Body column represents the body of the document obviously. It is this column that the full text indexing is enabled, as well as the column the statistical semantics are enabled.
The semantics database is attached and registered (which I believe some of the above queries confirms.
Check that the database you are using this with has a compatibility level of at least 2012 (Under database properties then Options).