Uncategorized Archives - Tech Insights https://reactconf.org/category/uncategorized/ Unveiling Tomorrow's Tech Today, Where Innovation Meets Insight Fri, 10 Feb 2023 16:49:46 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/reactconf.org/wp-content/uploads/2023/11/cropped-reactconf.png?fit=32%2C32&ssl=1 Uncategorized Archives - Tech Insights https://reactconf.org/category/uncategorized/ 32 32 230003556 How to Export Table Data to JSON Format in SQL Server https://reactconf.org/how-to-export-table-data-to-json-format-in-sql-server/ https://reactconf.org/how-to-export-table-data-to-json-format-in-sql-server/#respond Fri, 10 Feb 2023 16:49:46 +0000 http://www.sqlneed.com/?p=256 In this article we will learn How to Export Table Data to JSON Format in SQL Server. SQL Server   provides multiple ways to export data from a table into JSON …

The post How to Export Table Data to JSON Format in SQL Server appeared first on Tech Insights.

]]>
In this article we will learn How to Export Table Data to JSON Format in SQL Server. SQL Server   provides multiple ways to export data from a table into JSON format. Here’s a step by step procedure.

  1. Create a sample data table
CREATE TABLE Employee(
	Id int IDENTITY(1,1) NOT NULL,
	FirstName nvarchar(100) NOT NULL,
	LastName nvarchar(100) NOT NULL,
	designation nvarchar(50) NOT NULL,
	Title nvarchar(100) NOT NULL,
	Email nvarchar(25) NOT NULL,
	Role  nvarchar(15) NOT NULL,
	Password nvarchar(15) NOT NULL
	);

2. Insert sample data into the table Employee

INSERT INTO [dbo].[Employee]
           ([FirstName]
           ,[LastName]
           ,[designation]
           ,[Title]
           ,[Email]
           ,[Role]
           ,[Password])
     VALUES
           ('Mick','Fleming','Software Developer','Mr','Mick@example.com','Admin','123Admin'),
		   ('Stuart','Fleming','Software Developer','Mr','Stuart@example.com','Admin','123Admin');

FOR JSON Clause

For JSON Clause in a SELECT Statement to convert the data from a table into JSON format

SELECT * FROM EMPLOYEE FOR JSON AUTO

Result

[{"Id":5,"FirstName":"Mick","LastName":"Fleming","designation":"Software Developer","Title":"Mr","Email":"Mick@example.com","Role":"Admin","Password":"123Admin"},{"Id":6,"FirstName":"Stuart","LastName":"Fleming","designation":"Software Developer","Title":"Mr","Email":"Stuart@example.com","Role":"Admin","Password":"123Admin"}]

FOR JSON PATH

 To control over the format of the JSON output, use FOR JSON PATH.

SELECT * FROM EMPLOYEE FOR JSON PATH, Root('EmployeeList')
{"EmployeeList":[{"Id":5,"FirstName":"Mick","LastName":"Fleming","designation":"Software Developer","Title":"Mr","Email":"Mick@example.com","Role":"Admin","Password":"123Admin"},{"Id":6,"FirstName":"Stuart","LastName":"Fleming","designation":"Software Developer","Title":"Mr","Email":"Stuart@example.com","Role":"Admin","Password":"123Admin"}]}

The post How to Export Table Data to JSON Format in SQL Server appeared first on Tech Insights.

]]>
https://reactconf.org/how-to-export-table-data-to-json-format-in-sql-server/feed/ 0 2255
Subquery as column in Oracle SELECT Statements https://reactconf.org/selectsubqueryascolumn/ https://reactconf.org/selectsubqueryascolumn/#respond Sat, 16 Mar 2013 11:09:00 +0000 http://www.sqlneed.com/2013/03/16/subquery-as-column-in-oracle-select-statements/ This query I used aggregate functions with sub-queries SELECT (SELECT MAX(salary) FROM employees) AS Highest, (SELECT MIN(salary) FROM employees) AS Lowest, (SELECT COUNT(*) FROM employees) AS Employees, (SELECT SUM(salary) FROM …

The post Subquery as column in Oracle SELECT Statements appeared first on Tech Insights.

]]>

This query I used aggregate functions with sub-queries
SELECT
(SELECT MAX(salary) FROM employees) AS Highest,
(SELECT MIN(salary) FROM employees) AS Lowest,
(SELECT COUNT(*) FROM employees) AS Employees,
(SELECT SUM(salary) FROM employees) AS Total
FROM dual


Let us look at this with sub-queries at both the column level

and the CASE level. The following is the query:


SELECT
Employee_id, First_Name,
Salary AS salary,
ROUND((salary -(SELECT AVG(salary) FROM employees)),2) AS
avgcompare,
CASE
WHEN salary >= (SELECT AVG(salary) FROM employees) THEN
‘HIGH’
ELSE ‘LOW’
END AS paying
FROM employees
 

 

The post Subquery as column in Oracle SELECT Statements appeared first on Tech Insights.

]]>
https://reactconf.org/selectsubqueryascolumn/feed/ 0 2229