I used this Query to convert the data to JSON
SELECT *FROM tbl_subject FOR JSON AUTO
Iam getting the response as
when i click the response it is opening as XML file
how to change this xml to nvarchar data type
First of all, in SQL Server, JSON is not a data type in itself (XML is), but just a string representation.
What you see is due to how SQL Server Management Studio handles JSON when returned as a resultset. It is NOT xml, SSMS just slaps on an .xml file type, and prettifies the result. If you were to change how results were returned (Tools|Options|Query Results|SQL Server|General), you'd see it something like so:
JSON_F52E2B61-18A1-11d1-B105-00805F49916B
----------------------------------------------------------
[{"RowID":1,"UniversityID":1,"AcademicID":4,"CourseID":1}]
But this is just how SSMS returns result. If you were to execute your statement from an application, the result would be of string data type.
You could also change how you execute the query, to something like so:
DECLARE #nres nvarchar(max) = (SELECT * FROM dbo.tb_Subject FOR JSON AUTO)
SELECT #nres
Hope this helps!
Related
I am trying to load the Json file to SQL Server using Data Factory V2. Need to save the collection Reference of type array to string in SQL Server. In below figure 'Field' object consist of multiple fields. I need to store the object 'Keywords' as string type in SQL Server DB mapped to single column. I am not able to map the 'Keywords' or 'Field' to column
In Data Factory, we can not load the json data keywords array to each row for one column as json string in SQL Server.
What we can figured out is load all the json data to one row in SQL Server.
But that is an unconventional way:
Set the json file as Delimiter file format.
Set the column and row Delimiter with the character which not exist
in file.
Then the json data will be considered as a json string like bellow:
The output in SQL database:
I want to insert real time json payload into MySql DB. But I am unable to do so. I am trying to achieve it via mule 4. I am prompted the below error:-
Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
Please help.
MySql DB expects String as parameter in the SQL statement. Your component sends data as object. Word "binary" indicates it.
Send data as String. Convert your JSON object to string as described here https://simpleflatservice.com/mule4/Object_as_string.html
Example:
%dw 2.0
var x={abc:"xyz","key":"value"}
output application/java
---
write(x,'application/json')
In a web server, I'm running a query in Postgres that performs a select json_build_object of an aggregation(json_agg). I'm using Sequel to fetch this data, and I'm getting as a value an instance of Sequel::Postgres::JSONHash. Then, I perform a to_json in order to send it to the web client.
The output of this query is very big and I think that it could be more performant If I could grab the raw json response of postgres directly and send it to the client, instead of parsing it into JSONHash (which is done by Sequel) and then converting it again to json.
How could I do it?
Cast the json_build_object from json to text in the query: SELECT json_build_object(...)::text ...
I have a database table with a field "FileName" and a second field which is a base64 string (nvarchar(MAX)). It's an archive from my financial system. I want to convert this string back into a file using an Byte[] in a SSIS script task but i can't get the string value out of this object variable.
First I get the value from the SQL database in a SSIS variable (Base64Data). This variable is of type Object since the SQL type is nvarchar(MAX). I use sql statement: SELECT Base64Data FROM SubjectConnector WHERE FileName= '16-VMA-37041.pdf' which returns only one row. I then connect the Base64Data to a variable [User::Base64Data] in the Result Set window of the Execute SQL Task Editor. No problems here (at least so it seems).
But when I check the value of this object variable with:
MessageBox.Show(Dts.Variables["User::Base64Data"].Value.ToString());
it states:
System._ComObject
What it's going on? Is the result from the SQL query empty? How can I check this or what else is wrong?
Here's my SQL data
Please help.
Variable type Object is in fact ADO recordset, so you cannot get it directly with Dts.Variables... statement. I extracted NVARCHAR(MAX) value with FOR EACH enumerator for ADO.NET recordset, and fetched value from the first column into text variable.
We have stored an XML file in the database as blob field. Now we would like to see the data in the SQL editor.
SELECT CAST(response AS CHAR(10000)) FROM response_table
we see the column as ???
Could someone help me on how to get the values in the readable format?
Thanks.
It depends on your editor to show the blob response. I use Toad for mySql. Which shows the response and I can view it in different formats like HEX, ASC11 etc. Your query will remain same, not casting is needed.
SELECT response FROM response_table