Thank you very much for your help... but I cant create a table with the columns D1, D2 etc like..
CREATE TABLE #Temp1
(
clientid int,
tagid int,
tname varchar(max),
d1 int,
d2 int,
d3 int,
d4 int,
d5 int
)
since the number of those columns will change. every month the additional column will add to the table like D6, D7 etc.