Hi iam having two tables and i need to insert the values into a temp table according to the count as
IF(@COUNT>1)
BEGIN
insert into #temp_cols
SELECT M.ID_PK,
substring(M.NAME,1,1)+'_'+ N.NAME
FROM TEST_TABLE1 M WITH (NOLOCK)
LEFT JOIN TEST_TABLE2 N ON M.ID_PK=N.ID_FK
END
ELSE
BEGIN
insert into #temp_cols
SELECT M.ID_PK,
N.NAME
FROM TEST_TABLE1 M WITH (NOLOCK)
LEFT JOIN TEST_TABLE2 N ON M.ID_PK=N.ID_FK
END
where @count should be equal to select count(name) from test_table2 group by name which returns a group of columns and @count should take one column value at a time