I've tables and data as follow,declare @tRunNo table(idx tinyint identity(1,1), ryear char(4), rmonth char(2), runno int);/*ryear and rmonth is unique*/insert into @tRunno values('2010','05',1);insert into @tRunno values('2010','06',11);declare @t1 table(idx smallint identity(1,1), ddte datetime, wday char(7));insert into @t1 values('20100521','1011111');insert into @t1 values('20100524','1000111');insert into @t1 values('20100627','1011101');insert into @t1 values('20100701','1010011');1. How my SQL look's like to built output as follow,tid | ddte | wday----------------------------------------------------------TR100500000002 | 5/21/2010 | 1011111TR100500000003 | 5/24/2010 | 1000111TR100600000012 | 6/27/2010 | 1011101TR100700000001 | 7/1/2010 | 1011101
*tid value is generated from row in @tRunNo based on ddte2. After output above built, the current @tRunNo as followryear | rmonth | runno---------------------------------------2010 | 05 | 32010 | 06 | 122010 | 07 | 1
*you'll see, if row exist, it will update runno=runno+1. if not exist, it will insert starting from 1Really need help