Quote:
How to concadenate two tables into single table ?
...
string QueryStringData = "SELECT Name,city from Table1;
QueryStringData += "SELECT DoorNo from Table2";
You
CAN'T "concatenate" (join) tables by concatenating strings!
I completely agree with OriginalGriff's statements. There's no relationship between your tables! So, you need to define relationship between them to be able to get data from both tables. At this moment, you can workaround this by using below query (
NOT recommended):
DECLARE @table1 TABLE ([Name] VARCHAR(50),City VARCHAR(50))
INSERT INTO @table1 ([Name], City)
VALUES('Raja_1', 'Newyork_1'),
('Guna_2', 'claifornia_2'),
('Guna_3', 'claifornia_3')
DECLARE @table2 TABLE(DoorNo INT)
INSERT INTO @table2 (DoorNo)
VALUES(1), (2), (3),
(4), (5), (7)
SELECT t1.*, t2.*
FROM @table1 t1
INNER JOIN @table2 t2 ON CONVERT(INT, RIGHT(t1.Name, 1)) = t2.DoorNo
Result:
Name City DoorNo
Raja_1 Newyork_1 1
Guna_2 claifornia_2 2
Guna_3 claifornia_3 3
For further details, please see:
Joins (SQL Server) - SQL Server | Microsoft Docs[
^]
Visual Representation of SQL Joins[
^]