How can I put SELECT result set to SELECT column?

I have two tables: Job(ID,Name, etc.) and Address(ID, Job_ID, Name etc). I want to get result like this: [ { "Job_ID": 1, "JobName": "Test", "Addresses": [ { "ID": 1, "Name": "King street" }, { "ID": 2, "Name": "Queen`s street } ] } ] My current query that gets only one address for a job looks… Read More How can I put SELECT result set to SELECT column?

Add foreign column with default value

I need to add a foreign key column in an existing table using alter statement. And need to set default value to insert default in case of null. For that I added below alter query: ALTER TABLE COM.USER_GENERATED_TASK_LIST ADD Application_ID INTEGER NOT NULL CONSTRAINT DK_Application_ID DEFAULT (5) WITH VALUES, CONSTRAINT FK_Application_ID FOREIGN KEY (Application_ID) REFERENCES… Read More Add foreign column with default value

How to update a table column data, containing ( ' ) symble in data

I am getting error in microsoft sql server because the data I want to update is contains (‘) symbol in the data. update Employee_table set brokername=’Angie’s Broker’, where ID=7788; Please someome resolve the problem. >Solution : For single quotes used inside a string literal, you put another single quote before it. This is called "escaping"… Read More How to update a table column data, containing ( ' ) symble in data

I have a table id of 4000 thousand I want to put the last number in @a variable

declare @a Int, set @a=(SELECT TOP 1 UserTableID + 1 AS FisNo FROM ET_MalzemeveHareketleri order by UserTableID desc) select @a this is the code I have a table id of 4000 thousand I want to put the last number in @a variable >Solution : Do something like this declare @a Int; select @a = colname… Read More I have a table id of 4000 thousand I want to put the last number in @a variable

I have a table id of 4000 thousand I want to put the last number in @a variable

declare @a Int, set @a=(SELECT TOP 1 UserTableID + 1 AS FisNo FROM ET_MalzemeveHareketleri order by UserTableID desc) select @a this is the code I have a table id of 4000 thousand I want to put the last number in @a variable >Solution : Do something like this declare @a Int; select @a = colname… Read More I have a table id of 4000 thousand I want to put the last number in @a variable

How to add a column that shows the total number of rows in a table in SQL Server

I’ve got this table and I wish to add a column that gives the total number of rows in the table: Table now: Name PAT_ID ——————— Brian 123 Brian 356 Brian 3546 Brian 987 Desired output: Name PAT_ID TOTAL ———————————— Brian 123 4 Brian 356 4 Brian 3546 4 Brian 987 4 Thank you! >Solution… Read More How to add a column that shows the total number of rows in a table in SQL Server