Unable to view json file in SQL grid - sql-server

I am trying to generate json data through sql queries. I used "For Json Auto" to generate json.
One of the table contains html data with html tags. At the time of retrieving it in json it gives me error like :
TITLE: Microsoft SQL Server Management Studio
Unable to show XML. The following error happened:
Name cannot begin with the '\' character, hexadecimal value 0x5C. Line 1, position 426.
One solution is to increase the number of characters retrieved from the server for XML data. To change this setting, on the Tools menu, click Options.
BUTTONS:
OK
I have already set the XML character limit to unlimited. But still it gives me same error. Any help on this would be thankful.

The only way I was able to get around this was to switch to Results as Text and increase the number of characters per line greatly.

Related

Getting error due to '\'(escape char) as end of the column values during loading data into snowflake from sql server using COPY activity in ADF

I am using ADF copy activity to load data from SQL server to Snowflake, Getting an error during loading to snowflake as
ERROR:
"first error Found character '1' instead of field delimiter ','"
MY DATA:
c1 c2
rajesh\ 1
characher "" is treated as escape character while loading data into snowflake.
At sink side, I have added below 2 file format option and tried different values but it didn't work out.
ESCAPE_UNENCLOSED_FIELD
ESCAPE
Please share any suggestion how to handle this and Appreciate your support.
Thanks.
If you're using the GUI builder for the file format, scroll to the bottom section. In the drop-down boxes, you want to set the "Escape Unenclosed Field" to None. If there are still problems you can also try setting the "Escape Character" to None.
If you're using SQL to create or replace the file format, you want a section like this: ESCAPE = 'NONE' ESCAPE_UNENCLOSED_FIELD = 'NONE'

SqlServer Management Studio - Edit Top 200 - Max length of fields

I've a table with an nvarchar(MAX) column containing text formatted as Json of various length, around 15000; 2 records have a length of 53000 in that column and these are not shown using the "Edit top 200" command, but are shown using a Select query in a standard window.
Is there a length limit on the columns that is possible to read and edit using the "Edit top 200" command in Sql server management? I'm pretty sure there's a limit, but I can't find references about that in the documentation and I'd also expect some message in the field, a placeholder like "your data is too long to be shown here". Having just the field empty could be a little bit confusing.
Sql server 14.0.2037; Management studio 15.0.18390.0
Thanks

Scientific Notation Issue while loading data from Excel (xlsx) file to SQL Tables via SSIS

I'm loading data from excel file (.xlsx) to SQL table using SSIS package. For one column it's adding scientific notations in the data, it's already there in the excel file. But it's actual value is not loading to SQL table. I tried multiple option of derived columns, expressions etc. But I couldn't get the proper value.
This column has data of numeric and nvarchar values. Below is the example of the column.
ApplicationNumber
1.43E+15
923576663
25388447
TXY020732087
18794588
TXAP0000140343
**Actual Values -**
ApplicationNumber
1425600000000000
923576663
25388447
TXY020732087
18794588
TXAP0000140343
There is no issue with data coming from Business to Excel. But how we can handle this scenario in SSIS ?
I also tried (DT_I8)ApplicationNumber==(DT_I8)ApplicationNumber, But it giving values for the above
1.43E+15 -> 1.430000000000000 and not the 1425600000000000
One thing you can do is set the output in advanced editor of the excel source as decimal with a large scale, 20 digits for example:
UPDATE
to consider also strings in the same column you may need to redirect the error output as these will throw a conversion error:
in advanced editor:
Default output:
Error output:
Then you can update your database from both the default and the error output.
I faced this problem recently using SSIS too.
1- Change the column type in Excel to "Number"
2- Remove the decimal positions.
3- Upload the file using SSIS

SQL Server: How to Get Large amount of JSON from Store Procedure

I've created one store procedure that returns the JSON. But it not return complete JSON only limited JSON returned. I used "For JSON auto" after Select statement. Have any Solution to get all JSON?
if you are using any Cast or covert operations. Use VARCHAR(MAX) instead of VARCHAR().
I have seen this issue in such cases.
Also if you are using the print output, then it is possible that the text might get truncated, but you can use the Select or Output parameter instead.
make the output parameter of type nvarchar(max)
or check this link :
Format Query Results as JSON with FOR JSON (SQL Server)
This might help
I found my solution here: https://learn.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server?view=sql-server-ver15#output-of-the-for-json-clause (same as above, but a specific section)
The issue was that I thought SQL Server was returning a single row/cell of JSON data because that is how SSMS displayed it. The truth is that it chops it into multiple rows.
I was retrieving the data in .NET using ExecuteScalar(), but I needed to use ExecuteReader(), and concatenate all rows together. Once I did that, I could deserialize the JSON without issue.

SSRS how to format memo field

I'm pulling data from a SQL Server 2008 R2 database and one of the fields is a memo field.
When the data is displayed it comes out in the format DATE/USER/then the message. There is a line break and this repeats. For example:
30/10/2013 11:34 TRACEY : order Created
30/10/2013 11:38 AUTO : order Authorised
30/10/2013 11:40 TRACEY : order Issued
30/10/2013 11:41 TRACEY : order processed
I don't have an control in changing SQL database tables/fields.
I want to be able to format this ugly block of text but really struggling to find a solution - for display in SSRS report. Is there any way I can add a space between each line? Or strip out certain words or complete lines based on some specific parameter?
I just don;t seem to be enable control formatting of memo fields. Any help appreciated.
You can write your own function (in the report' declaration) which will perform the formatting, but this is not the simple task. After this you can call this function and receive a formatted text.
Samples of this you can find in the following articles:
http://technet.microsoft.com/en-us/library/ms156028.aspx
http://technet.microsoft.com/en-us/library/ms155798%28v=sql.100%29.aspx

Resources