序号问题
Id,   FormatId,   F1   ,F2 
 Id序号我设了自动加一,FormatId我想他也象这样 "SL000001 ", 
 当Insert时就加1,FormatId我想他也能自动加一 "SL000001 ", "SL000002 "... 
 能用一条sql什么办法实现.最好不要用中间表。有什么好方法? 
 谢谢!
------解决方案--------------------create table #test 
 (id int identity, 
 FormatId as  'SL '+right(10000000+id,6), 
 F1 varchar(50)) 
 go 
 insert #test(F1) select  '1 ' 
 union all select  '2 '     
 select * from #test   
 drop table #test
------解决方案--------------------declare @count int 
 declare @sql varchar(8000) 
 select @sql =  'sl00000 '+convert(varchar(8000),@count,101)   
 这个不是你的答案,你可以根据这个改
------解决方案--------------------最好不要用计算列,可以用触发器实现... 
 这样的一般都是通过软件实现的 
 这里有个列子: 
 http://blog.csdn.net/roy_88/archive/2006/12/01/1424370.aspx
------解决方案--------------------對於 wangdehao(找找找(现在很幸福)) paoluo(一天到晚游泳的鱼)的答案,如果ID,Formatid 不同步就不行了。
------解决方案--------------------我给各不一样的实现   
 CREATE TABLE T (Id INT IDENTITY(1,1), FormatId VARCHAR(8), F1 VARCHAR(4) ,F2 VARCHAR(4))   
 INSERT INTO T  
 SELECT  'SL ' +  
 	RIGHT( '000000 '+ 
 		CAST( 
 			(CAST( 
 				RIGHT( 
 					ISNULL((SELECT TOP 1 FormatId FROM T ORDER BY FormatId DESC),  'SL000000 ') 
 				, 6) 
 			AS INT)	+1) 
 		 AS VARCHAR) 
 	, 6) 
 , '2 ',  '3 '   
 SELECT * FROM T   
 DROP TABLE T 
------解决方案--------------------wangdehao(找找找(现在很幸福)) paoluo(一天到晚游泳的鱼)的答案都是对的. 
 ------------------------------ 
 Create Table TEST 
 (Id	Int , 
  FormatId As   'SL ' + Right(1000000 + Id, 6), 
  F1	Int, 
  F2	Int) 
 GO 
 最后前台控制ID
------解决方案--------------------Create Trigger UpdateFormatId On TEST 
 Instead Of Insert 
 As 
 Begin 
 	Insert TEST (FormatId, F1, F2) 
 	Select  'SL ' + Right(1000000 + Id, 6), F1, F2 From Inserted 
 End 
 GO 
 --測試 
 Insert TEST(F1, F2) Select 1, 2 
 Union All Select 2, 3   
 Select * From TEST 
 GO 
 --刪除測試環境 
 Drop Table TEST 
 --結果 
 /* 
 Id	FormatId	F1	F2 
 1	SL000001	1	2 
 2	SL000002	2	3 
 */   
 我测试的时候好像不行哟。  
------解决方案--------------------不知道怎么回事。
------解决方案--------------------不好意思,那個觸發器的確是不行。     
 --建立測試環境 
 Create Table TEST 
 (Id	Int Identity(1, 1), 
  FormatId Char(8), 
  F1	Int, 
  F2	Int) 
 GO 
 --建立觸發器 
 Create Trigger UpdateFormatId On TEST 
 After Insert 
 As 
 Begin 
 	Update A Set FormatId =  'SL ' + Right(1000000 + A.Id, 6) From TEST A Inner Join Inserted B On A.Id = B.Id 
 End 
 GO 
 --測試 
 Insert TEST(F1, F2) Select 1, 2 
 Union All Select 2, 3   
 Select * From TEST 
 GO 
 --刪除測試環境 
 Drop Table TEST 
 --結果 
 /* 
 Id	FormatId	F1	F2 
 1	SL000001	1	2 
 2	SL000002	2	3 
 */   
------解决方案--------------------declare @t table(id int identity(1,1),FormatId as  'SL '+left( '000000 ',6-len(id))+cast(id as varchar),value varchar(10))