Can I cast inside a sqlserver containsregex? - sql

I'm using an older PHP driver for mssql and am trying to filter out results using the ContainsRegExp command. The issue is that the field I'm comparing is ntext and it causes the query to fail. Is it possible to do a cast inside the ContainsRegExp command somthing like:
... AND Field1.ContainsRegExp(CAST(Field1 AS TEXT) AS Field1Test,\'html\')=1';
The full query statement:
'SELECT ReportID, ReportDate, CAST(ReportData AS TEXT) AS TextData FROM Database WHERE ReportData.ContainsRegExp(CAST(ReportData AS TEXT),\'html\')=1';
The error I see is:
message: Cannot call methods on ntext. (severity 15)

ContainsRegExp is not a standard SQL Server command. So I'm not really sure how you've arrived at that statement, but it's not T-SQL.
My guess is that somewhere along the line a similar command has been used with a CLR type - because the syntax you are using (Field.Operation()) is used for calling methods on CLR types.

Related

Problem running embedded firebird sql query in LibreOffice

I am trying to run the following Firebird SQL query in LibreOffice, which has embedded Firebird:
SELECT RDB$GET_CONTEXT('SYSTEM', 'ENGINE_VERSION') AS "VERSION"
FROM "RDB$DATABASE";
I get the message Syntax error in SQL statement. Can anyone tell me what I am doing wrong? This works in FlameRobin, but not in LibreOffice.
The error "Syntax error in SQL statement" is a HSQLDB error. So, first, make sure your LibreOffice Base project is actually created as a Firebird Embedded project.
I was able to reproduce the error in LibreOffice Base 6.4.4.2 with a Firebird Embedded project. It looks like LibreOffice first tries to parse the query using HSQLDB (probably to be able to transform HSQLDB syntax to Firebird syntax), and only then forwards it to Firebird.
The cause of the error is the $ in RDB$GET_CONTEXT which is not a valid character in an unquoted object name in the HSQLDB SQL syntax, while it is valid in the Firebird SQL syntax. Normally, double quoting the specific object name would solve this, but RDB$GET_CONTEXT is not actually a function, but a syntax construct, so it can't be quoted in Firebird.
To be able to execute this query, you need to enable the 'Run SQL command directly' option in the SQL View, either under Edit > 'Run SQL command directly', or using the 'Run SQL command directly' button in the toolbar (database icon with >_).

How do I convert this standard sql to legacy sql code in bigquery?

CREATE TEMPORARY FUNCTION
s2id(lit FLOAT64,
low FLOAT64,
level FLOAT64)
RETURNS STRING
LANGUAGE js AS """
return litLowToId(lit,low,level);
"""
OPTIONS
(library="test.js");
Big query is highlighting the lit part without telling me why. It just says encountered "" in line 2. What is happening here?
Big query is highlighting the lit part without telling me why. It just says encountered "" in line 2. What is happening here?
The reason you are getting above error in UI is because you are using Legacy SQL
Switch to Standard SQL (uncheck Use Legacy SQL checkbox in Options Panel [in Classic UI] or check Standard SQL dialect radiobox [in new UI] )
Alternatively you can just add below line to the very top (as a first line) of your whole code
See Enabling Standard SQL for more details
#standardSQL
In addition you have to provided a valid path - something like below
library="gs://my-bucket/path/to/test.js"
And finally, you need to have actual query below your function
How do I convert this standard sql to legacy sql code in bigquery?
I strongly recommend you to stay with BigQuery Standard SQL
In case you you locked by existing legacy sql code - you might rather want to migrate your sql query from legacy to standard instead
In any case UDF for BigQuery legacy and standard dialect are quite different - see Differences in user-defined JavaScript functions

Functions not working in Table Adapter Query bulider

I'm using Visual Studio 2013, I try to use some function (like "cast" and Year ) in Table Adapter Query Builder (in DataSet.XSD ). I get erroe messgae every time. I run the sql statement on other sql programs and it's work fine. did anyone face this problem?
Is your dataSource SQL Server or SQLite. If you are using SqLite then functions such as Year(),Cast() are not allowed.
If you are using SQLite then please find below link for date time function reference,
https://www.sqlite.org/lang_datefunc.html
As you have asked for Cast function, there is SO post describing the cast function, which is similar to that of SQL Server
SQLite supports CAST and:
Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the
encoding of the database connection.
So you can do things like this:
select cast(some_integer_column as text) from some_table;
Or, depending on what you're trying to do, you could just treat the
numbers as strings and let SQLite coerce the types as it sees fit:
select some_int || ' pancakes' from some_table; select some_int || ''
from some_table;
SQLite does not have this function YEAR(...). Try strftime('%Y', degrees.ExamDate) = '2017' instead.

How to call SQL Command with custom parameters in field (Crystal Reports)?

I have a custom SQL expression with some parameters.
I've added it to Field Explorer correctly.
But I couldn't find an example of syntax for using pre-defined parametrized SQL command with my own non-default parameters.
For example, there is a SQL expression like this (it's body of SQL command):
select count(*) from table A where A.col1 > {?param}
I want to create a set of fields with different parameters.
What should I to do?
Is it possible?
Version of CR is 11, SQL syntax is Oracle SQL.
Thank in advance.
You can't use parameter field in a SQL-expression field.
You can, however, use a parameter field with a Command object (assuming that the parameter was defined in the Command object)

Simple question on a SQL create table

I was actually in process of creating a sample table in my test database when somehow I missed out on proper syntax and came up with this statement for create table -
CREATE TABLE A (id as INT, column1 as nvarchar(10))
and when I tried to execute this statement, I got the error below -
'nvarchar' is not a recognized built-in function name.
Altough, I found that I should not have used "as" in the column declaration and corrected it, I am now curious on why I got this error for only nvarchar and not for INT.
Also why this error instead of a incorrect syntax or something like that.
Thanks in advance.
AS is used to define computed columns. Therefore SQL Server expects an expression here, and this "looks" like a function call.
Computed columns info on MSDN for SQl Server 2005