Hi I'm pulling data within Data Manager and which is coming via Salesforce so the data type and limits are set in Salesforce which I have no control over. I would like to know how I can limit the the amount of data coming in and inserted into the MS SQL. This is the error:
[42000]Microsoft SQL Server Native Client 10.0
The size (32000) given to the column 'Description' exceeds the maximum allowed for any data type (8000).
And this is my query which pulls the data:
SELECT "Id",
"IsDeleted",
"Name",
"ParentId",
"Type",
"Status",
"StartDate",
"EndDate",
"CurrencyIsoCode",
"ExpectedRevenue",
"BudgetedCost",
"ActualCost",
"Description",
"ExpectedResponse",
"NumberSent",
"IsActive",
"NumberOfLeads",
"NumberOfConvertedLeads",
"NumberOfContacts",
"NumberOfResponses",
"NumberOfOpportunities",
"NumberOfWonOpportunities",
"AmountAllOpportunities",
"AmountWonOpportunities",
"OwnerId",
"CreatedDate",
"CreatedById",
"LastModifiedDate",
"LastModifiedById",
"SystemModstamp",
"LastActivityDate",
"CampaignMemberRecordTypeId",
"Date_of_Event__c",
"Venue__c"
FROM "SF Schema"."Campaign"
Is there anyway to set limit on the "Description" the max is 8000.
Thanks!
You can get first 8000 characters using LEFT()
SELECT LEFT(Description,8000) AS Description FROM YourTable
When is this eror happening?
Your error is not comming from your data, but from the DDL of the "SF Schema"."Campaign" table.
How is it possible for that table to have a column of size 32000? Where was it defined?
This little sample code shows how to reproduce your error message.
DECLARE #table TABLE
(
dummy nvarchar(32000)
)
This produces this output:
Msg 131, Level 15, State 2, Line 3
The size (32000) given to the column 'dummy' exceeds the maximum allowed for any data type (8000).
Maybe LEFT, as stated in another answer helps you, but I guess that you are going to get the same error, because of the problem being in the definition of the source table.
LEFT on the MSDN: http://msdn.microsoft.com/es-es/library/ms177601.aspx
Related
A proprietary third-party application stores JSON strings in it's database like this one:
{"state":"complete","timestamp":1614776473000}
I need the timestamp and found out that
DB2 offers JSON functions. Since it's stored as string in the PROF_VALUE column, I guess that converting with SYSTOOLS.JSON2BSON is required, before I can use JSON_VAL to fetch the timestamp:
SELECT SYSTOOLS.JSON_VAL(SYSTOOLS.JSON2BSON(PROF_VALUE), "timestamp", "f")
FROM EMPINST.PROFILE_EXTENSIONS ext
WHERE PROF_PROPERTY_ID = 'touchpointState'
This causes an error that timestamp is invalid in the used context ( SQLCODE=-206, SQLSTATE=42703, DRIVER=4.26.14). The same error is thown when I remove the JSON2BSON call like this
SELECT SYSTOOLS.JSON_VAL(PROF_VALUE, "timestamp", "f")
Also not working with the same error (different data-types):
SELECT SYSTOOLS.JSON_VAL(SYSTOOLS.JSON2BSON(PROF_VALUE), "state", "s:1000")
SELECT SYSTOOLS.JSON_VAL(PROF_VALUE) "state", "s:1000")
I don't understand this error. My syntax is like the documented JSON_VAL ( json-value , search-string , result-type) and it is the same like in the examples, where they show how to fetch the name field of an object.
I also played around a bit with JSON_TABLE to use raw input data for testing (instead of the database data), but it seems not suiteable for that.
SELECT *
FROM TABLE(SYSTOOLS.JSON_TABLE( SYSTOOLS.JSON2BSON('{"state":"complete","timestamp":1614776473000}'), 'state','s:32')) DATA
This gave me a table with one row: Type = 2 and Value = complete.
I had two problems in my query: First it seems that double quotes " are for object references. I wasn't aware that there is any difference, because in most databases I used yet, both single ' and double quotes " are equal.
The second problem is, that JSON_VAL needs to be called without SYSTOOLS, but the reference is still needed on SYSTOOLS.JSON2BSON(PROF_VALUE).
With those changes, the following query worked:
SELECT JSON_VAL(SYSTOOLS.JSON2BSON(PROF_VALUE), 'timestamp', 'f')
FROM EMPINST.PROFILE_EXTENSIONS ext
WHERE PROF_PROPERTY_ID = 'touchpointState'
Currently, I am trying to extract metadata from an OLAP cube in SQL Server (via a linked server) using this simple query:
select *
into [dbo].[columns_metadata]
from openquery([LINKED_SERVER], '
select *
from $System.TMSCHEMA_COLUMNS
')
But in the result set, there is a column named RefreshedTime with values 31.12.1699 00:00:00.
Because of this value, the query gives this error message:
Msg 8114, Level 16, State 9, Line 1 Error converting data type (null)
to datetime.
The problem is that I need to run the query without specifying the columns in the SELECT statement.
Do you know a trick to avoid this error?
I know you wanted not to have to mention the columns explicitly, but in case nobody can suggest a way to have it handle the 1699-12-31 dates, then you can fallback to this:
select *
into [dbo].[columns_metadata]
from openquery([LINKED_SERVER], '
SELECT [ID]
,[TableID]
,[ExplicitName]
,[InferredName]
,[ExplicitDataType]
,[InferredDataType]
,[DataCategory]
,[Description]
,[IsHidden]
,[State]
,[IsUnique]
,[IsKey]
,[IsNullable]
,[Alignment]
,[TableDetailPosition]
,[IsDefaultLabel]
,[IsDefaultImage]
,[SummarizeBy]
,[ColumnStorageID]
,[Type]
,[SourceColumn]
,[ColumnOriginID]
,[Expression]
,[FormatString]
,[IsAvailableInMDX]
,[SortByColumnID]
,[AttributeHierarchyID]
,[ModifiedTime]
,[StructureModifiedTime]
,CStr([RefreshedTime]) as [RefreshedTime]
,[SystemFlags]
,[KeepUniqueRows]
,[DisplayOrdinal]
,[ErrorMessage]
,[SourceProviderType]
,[DisplayFolder]
from $System.TMSCHEMA_COLUMNS
')
i have a column in table which contain data like XML,i would like to get data in rows.
My table data as-
select printDataColumn from Mytable
It returns value-
<PrintData>
<Line1>.MERCHANT ID: *****4005</Line1>
<Line2>.CLERK ID: ADMIN</Line2>
<Line3>.</Line3>
<Line4>. VOID SALE</Line4>
<Line5>.</Line5>
<Line6>.VISA ************0006</Line6>
<Line7>.ENTRY METHOD: SWIPED</Line7>
<Line8>.DATE: 03/05/2019 TIME: 16:57:20</Line8>
<Line9>.</Line9>
<Line10>.INVOICE: 1551785225020</Line10>
<Line11>.REFERENCE: 1008</Line11>
<Line12>.AUTH CODE: 08354A</Line12>
<Line13>.</Line13>
<Line14>.AMOUNT USD$ 1.14</Line14>
<Line15>. ==========</Line15>
<Line16>.TOTAL USD$ 1.14</Line16>
<Line17>.</Line17>
<Line18>. APPROVED - THANK YOU</Line18>
<Line19>.</Line19>
<Line20>.I AGREE TO PAY THE ABOVE TOTAL AMOUNT</Line20>
<Line21>.ACCORDING TO CARD ISSUER AGREEMENT</Line21>
<Line22>.(MERCHANT AGREEMENT IF CREDIT VOUCHER)</Line22>
<Line23>.</Line23>
<Line24>.</Line24>
<Line25>.</Line25>
<Line26>.x_______________________________________</Line26>
<Line27>. Merchant Signature</Line27>
<Line28>.</Line28>
</PrintData>
but i want to use this information in another way like that
MERCHANT ID: *****4005
CLERK ID: ADMIN
SALE
AMEX ***********1006
ENTRY METHOD: CHIP
DATE: 03/07/2019 TIME: 14:37:23
INVOICE: 1551949638173
REFERENCE: 1005
AUTH CODE: 040749. . . . .and so on.
any help is appreciable.
Besides the fact, that it always is a good idea to use the appropriate type to store your data, you can use a cast on the fly to use your xml-like-data with XML methods:
DECLARE #tbl TABLE(ID INT IDENTITY,PrintData VARCHAR(4000));
INSERT INTO #tbl VALUES
('<PrintData>
<Line1>.MERCHANT ID: *****4005</Line1>
<Line2>.CLERK ID: ADMIN</Line2>
<Line3>.</Line3>
<Line4>. VOID SALE</Line4>
<!-- more lines -->
</PrintData>');
SELECT t.ID
,A.Casted.value(N'(/PrintData/Line1/text())[1]','nvarchar(max)') AS Line1
FROM #tbl t
CROSS APPLY(SELECT CAST(t.PrintData AS XML)) A(Casted);
In this case I use CROSS APPLY to add a column A.Casted to the result set, which is a row-wise casted XML.
This will break, in cases of invalid XML (of course). You might try TRY_CAST instead. This would return NULL, but will hide data errors...
Some more background
The cast to XML is a rather expensive operation. Doing this whenever you want to read out of your data is some heavy load for your server. Furthermore, using VARCHAR is prone to two major errors:
If there are foreign characters you might get question marks
If the XML is not valid, you will not see it - until you use it.
If possible, try to change the table's design to use native XML.
And one more hint
It is a bad approach to name-number elements (same for columns). Instead of <Line1><Line2><Line3> better use <Line nr="1"><Line nr="2"><Line nr="3">...
I'm making a tiny webapp to see what are the pub's specials around you and I have a very silly problem with my SQL query to fusion table.
Here is my table and her is my query:
ST_INTERSECTS(address, CIRCLE(LATLNG(-33.898672999999995, 151.2063809), 300))
AND type IN ('food','drinks')
AND days CONTAINS 'tuesday'
AND from <= 2000
AND to >= 2000
My problem is with the from and to, if I remove them my query is fine and if I simplify them (remove from and put just to > 0) my query is still wrong.
As you can see in my fusion table, from and to are both numbers so I really don't get what's wrong.
EDIT:
So I'm using https://developers.google.com/apis-explorer/#p/fusiontables/v2/fusiontables.query.sql to test my queries:
Good query (200 OK):
SELECT *
FROM 1BHnaan3YfSDq9_LzjthDXjj5dzJZANjLSb8JHPl5
WHERE
ST_INTERSECTS(address, CIRCLE(LATLNG(-33.898672999999995, 151.2063809), 300))
AND type IN ('food','drinks')
AND days CONTAINS 'tuesday'
Bad query:
SELECT *
FROM 1BHnaan3YfSDq9_LzjthDXjj5dzJZANjLSb8JHPl5
WHERE
ST_INTERSECTS(address, CIRCLE(LATLNG(-33.898672999999995, 151.2063809), 300))
AND type IN ('food','drinks')
AND days CONTAINS 'tuesday'
AND from <= 1619
AND to >= 1619
I get this error but I don't see what's wrong because <= is in the docs:
{
"error": {
"errors": [
{
"domain": "fusiontables",
"reason": "badQueryCouldNotParse",
"message": "Invalid query: Parse error near 'from' (line 1, position 218).",
"locationType": "parameter",
"location": "q"
}
],
"code": 400,
"message": "Invalid query: Parse error near 'from' (line 1, position 218)."
}
}
from & to are reserved words in fusion table, here is the list of reserved words:
AND
ASC
AS
BY
CASE
CIRCLE
CONTAINS
CONTAIN
CREATE
DELETE
DESCRIBE
DESC
DOES
DROP
ENDS
EQUAL
FROM
GROUP
IGNORING
IN
INSERT
INTO
LATLNG
LIKE
LIMIT
MATCHES
NEAR
NOT
OFFSET
ORDER
POLYGON
RECTANGLE
ROWID
SELECT
SET
SHOW
SKIP
ST_DISTANCE
ST_INTERSECTS
STARTS
TABLES
TABLE
TO
UPDATE
VALUES
VIEW
WHERE
WITH
ID
NUMBER
DOCID
STRING
I figured it out because they were blue in the syntax highlighting in my question.
If you try that query from the Fusion Tables UI, you also see no results, because no values match those criteria. The days are "monday" and "tuesday", and the times are 1130-1400 and 1800-2359.
I'm working on a IBM iseries v6r1m0 system.
I'm trying to execute a very simple query :
select * from XG.ART where DOS = 998 and (DES like 'ALB%' or DESABR like 'ALB%')
The columns are:
DOS -> numeric (3,0)
DES -> Graphic(80) CCSID 1200
DESABR -> Garphic(25) CCSID 1200
I get :
SQL State : 58004
SQL Code : -901
Message : [SQL0901] SQL System error.
Cause . . . . . : An SQL system error has occurred. The current SQL statement cannot be completed successfully. The error will not prevent other SQL statements from being processed. Previous messages may indicate that there is a problem with the SQL statement and SQL did not correctly diagnose the error. The previous message identifier was CPF4204. Internal error type 3107 has occurred. If precompiling, processing will not continue beyond this statement.
Recovery . . . : See the previous messages to determine if there is a problem with the SQL statement. To view the messages, use the DSPJOBLOG command if running interactively, or the WRKJOB command to view the output of a precompile. An application program receiving this return code may attempt further SQL statements. Correct any errors and try the request again.
If I change DES into REF (graphic(25)), it works...
EDIT :
I run some tests this afternoon, and it is very strange :
Just after the creation of the table/indexes, I have no errors.
If I insert some datas : error
If I clear the table : error
If I remove an index (see below) : it works (with or without datas)
!!
The index is :
create index XG.GTFAT_ART_B on XG.ART(
DOS,
DESABR,
ART_ID
)
Edit 2 :
Here is the job log (sorry, it is in French...)
It sais :
Function error X'1720' in machine instruction. Internal snapshot ID 01010054
Foo file created in library QTEMP.
*** stuff with the printer
DBOP *** FAILED open. Exception from call to SLIC$
Internal error in the query processor file
Sql system error
I finally contacted IBM.
It was an old bug from v5.
I have installed the latest PTF, and now, it works.
You need to use the GRAPHIC scalar function to convert your character literals on the LIKE predicate.
CREATE TABLE QTEMP/TEST (F1 GRAPHIC(80))
INSERT INTO QTEMP/TEST (F1) VALUES (GRAPHIC('TEST'))
SELECT * FROM QTEMP/TEST WHERE F1 LIKE GRAPHIC('TE%')
I know this guy got his problem fixed with an update. But here is something that worked for me that might work for the next guy here who has the problem.
My problem query had a lot of common table expressions. Most of them did not create tables with a whole lot of records. So if I figured that the maximum number of records a CTE would make was 1000, I added a "Fetch first 9999 rows only" to it. I knew that the CTE couldn't possibly have more rows than that. I guess the query optimizer had less to think about with that added.
If you have that problem and you don't have the option to upgrade or talk to IBM, I hope this help you.
For other people getting this errore, I encountered it on an IBM i Series v7r3, when tried an UPDATE, retrieving the value to be set on a field using a inner SELECT where multiple results where reduced to 1, using DISTINCT. I solved the problem removing DISTINCT and adding FETCH FIRST 1 ROW ONLY at the end of the inner SELECT.
E.g.: changed from
UPDATE MYTABLE AS T1
SET T1.FIELD1 = (
SELECT DISTINCT T2.FIELD5
FROM MYTABLE AS T2
WHERE T1.FIELD2 = T2.FIELD2
AND T1.FIELD3 = T2.FIELD3
)
WHERE T1.FIELD4 = 'XYZ'
to
UPDATE MYTABLE AS T1
SET T1.FIELD1 = (
SELECT T2.FIELD5
FROM MYTABLE AS T2
WHERE T1.FIELD2 = T2.FIELD2
AND T1.FIELD3 = T2.FIELD3
FETCH FIRST 1 ROW ONLY
)
WHERE T1.FIELD4 = 'XYZ'