How to get the length of the contents of a varbinary field with SQL in Advantage Database Server db? - sql

Does anyone know if it is possible to get the length of the contents of a varbinary field using SQL with Advantage Database Server V11?
Regards

The obvious function to look for would be LENGTH(field) or LEN(field) (see online help).
If those only work on character fields, then you can always cast.

Related

Query remote oracle CLOB data from MSSQL

I read different posts about this problem but it didn't help me with my problem.
I am on a local db (Microsoft SQL Server) and query data on remote db (ORACLE).
In this data, there is a CLOB type.
CLOB type column shows me only 7 correct data the others show me <null>
I tried to CAST(DEQ_COMMENTAIRE_REFUS_IMPORT AS VARCHAR(4000))
I tried to SUBSTRING(DEQ_COMMENTAIRE_REFUS_IMPORT, 4000, 1)
Can you help me, please ?
Thank you
No MSSQL but in my case we were pulling data into MariaDB using the ODBC Connect engine from Oracle.
For CLOBs, we did the following (in outline):
Create PLSQL function get_clob_chunk ( clobin CLOB, chunkno NUMBER) RETURN VARCHAR2.
This will return the the specified nth chunk of 1000 chars for the CLOB.
We found 1,000 worked best with multibyte data. If the data is all plain text single byte that chunks of 4,000 are safe.
Apologies for the absence of actual code, as I'm a bit rushed for time.
Create a Oracle VIEW which calls the get_clob_chunk function to split the CLOB into 1,000 char chunk columns chunk1, chunk2, ... chunkn, CAST as VARCHAR2(1000).
We found that Oracle did not like having more than 16 such columns, so we had to split the views into sets of 16 such columns.
What this means is that you must check what the maximum size of data in the CLOB is so you know how many chunks/views you need. To do this dynamically adds complexity, needless to say.
Create a view in MariaDB querying the view.
Create table/view in MariaDB that joins the chunks up into a single Text column.
Note, in our case, we found that copying Text type columns between MariaDB databases using the ODBC Connect engine was also problematic, and required a similar splitting method.
Frankly, I'd rather use Java/C# for this.

What is the best SQL type to use for a large string variable?

Apologies for the rather basic question.
I have an error string that is built dynamically. The data in the string is passed by various third parties so I don't have any control, nor do I know the ultimate size of the string.
I have a transaction table that currently logs details and I want to include the string so that I can reference back to it if necessary.
2 questions:
How should I store it in the database?
Should I do anything else such as contrain the string in code?
I'm using Sql Server 2008 Web.
If you want to store non unicode text, you can use:
varchar(max) or nvarchar(max)
Maximum length is 2GB.
Other alternatives are:
binary or varbinary
Drawbacks: you can't search into these fields and index and order them
and the maximum size : 2GB.
There are TEXT and NTEXT, but they will be deprecated in the future,
so I don't suggest to use them.
They have the same drawbacks as binary.
So the best choice is one of varchar(max) or nvarchar(max).
You can use SQL Server nvarchar(MAX).
Check out this too.
Eventualy, you can enable and use a FILESTREAM feature of SQL Server 2008 (it's supported by WEB edition), and deal with extra large amount of data in sense of documents.
Of course, you need to be sure that you will use a benefit of this service.

Data Type Mapping

I need to store XML data to database(MS SQL Server). The data type defined in the column is text.
I need to know the the equalent datatype for text. I have tried with adLongVarChar but it does not works. Also I tried with adLongVarWChar(nText). But both are not working.
Need help.
Thanks.
In case your are using SQL Server 2005 or higher then you might prefer going for the XML data type. Read more of it here http://www.codeproject.com/KB/database/XMLdDataType.aspx
Also going forward avoid using ntext and text data types as they would be removed from future versions of SQL Server. Instead go for nvarchar(max) or varchar(max). Read on this here http://msdn.microsoft.com/en-us/library/ms187993.aspx
cheers
TSQL datatype for a string is varchar or nvarchar (unicode). To specify the length of the string, varchar(50).
Also note there is an XML datatype in SS 2008 (2005?).

Why is maximum length of varchar less than 8,000 bytes?

So I have a stored procedure in a SQLServer 2005 database, which retrieves data from a table, format the data as a string and put it into a varchar(max) output variable.
However, I notice that although len(s) reports the string to be > 8,000, the actual string I receive (via SQLServer output window) is always truncated to < 8,000 bytes.
Does anybody know what the causes of this might be ? Many thanks.
The output window itself is truncating your data, most likely. The variable itself holds the data but the window is showing only the first X characters.
If you were to read that output variable from, for instance, a .NET application, you'd see the full value.
Are you talking about in SQL Server Management Studio? If so, there are some options to control how many characters are returned (I only have 2008 in front of me, but the settings are in Tools|Options|Query Results|SQL Server|Results to Grid|Maximum Characters Retrieved and Results to Text|Maximum number of characters displayed in each column.
The data is all there, but management studio isn't displaying all of the data.
In cases like this, I've used MS Access to link to the table and read the data. It's sad that you have to use Access to view the data instead of Management Studio or Query Analyzer, but that seems to be the case.
However, I notice that although len(s) reports the string to be > 8,000
I have fallen for the SQL Studio issue too :) but isn't the maximum length of varchar 8,000 bytes, or 4,000 for nvarchar (unicode).
Any chance the column data type is actually text or ntext and you're converting to varchar?

Can source code examples be kept in a SQL database while retaining all formatting? If so

Can source code examples be kept in a SQL database while retaining all formatting (tabs, newlines, etc.)? If so what data type would be used?
Yes, use a TEXT type (or MEDIUMTEXT or LONGTEXT - you get the idea)
A BLOB type (varbinary) would definitely work, although databases shouldn't mangle text that's stored as varchar either.
The best in Sql Server: nvarchar(max)
You can upload this into a blob data type. SQL 2008 comes with the capability of storing the entire executable file in the database.