How to join two literal tables together in T-SQL

In this answer it is shown how a literal table can be created. However, I want to perform a full outer join or inner join on two literal tables, but I cannot figure out the syntax of the literal table after the join. I have tried several variations on this: SELECT * FROM (VALUES (1),… Read More How to join two literal tables together in T-SQL

Msg 8114, Level 16, State 5, Line 2 Error converting data type

Can you help me to do this view correctly? code: SELECT CustomerName, C_CUR, SUM(BILL_AMT) AS B_AMT, C_CODE FROM dbo.BILLS WHERE (BILL_TYPE = 2) GROUP BY C_CODE, C_CUR, CustomerName UNION ALL SELECT C_CODE, SUM(BILL_AMT) AS RT_AMT, C_CUR, CustomerName FROM dbo.RTN_BILLS WHERE (BILL_TYPE = 2) GROUP BY C_CODE, C_CUR, CustomerName error: Msg 8114, Level 16, State 5,… Read More Msg 8114, Level 16, State 5, Line 2 Error converting data type

CONVERT function cannot convert string to DATETIME

I have a string like this that I want to convert to a DATETIME value. DECLARE @eh NVARCHAR(MAX) = ‘2021-07-19 14:00:39.0000000’ So this is what I tried: DECLARE @eh NVARCHAR(MAX) = ‘2021-07-19 14:00:39.0000000’ SELECT CONVERT(DATETIME, @eh) But it always returns this error: Msg 241, Level 16, State 1, Line 3 Conversion failed when converting date… Read More CONVERT function cannot convert string to DATETIME

Is there a way in SQL Server to get a string from a group of strings based on some predicate?

I’m trying to retrieve the status for a multi-step process which is stored in a sql server db. Each step is a record in a table. When a client wants to know the status of that process, I would like to retrieve the statusses for all steps and have my query return a status of… Read More Is there a way in SQL Server to get a string from a group of strings based on some predicate?

Insert JSON into SQL table

I have the following SQL Table 1: id name gender age country ambition 1 Peter Male 20 Italy Doctor 2 Angeli Female 30 Australia Lawyer I want to insert into another table like this method. Output : SQL Table 2 id name details json 1 Peter {"gender":"Male","age":"20","country":"Italy","ambition":"Doctor"} 2 Angeli {"gender":"Female","age":"30","country":"Australia","ambition":"Lawyer"} Any suggestions on how to… Read More Insert JSON into SQL table