自動生成符号化、日付;ランダム生成時間

5642 ワード

自動生成エンコーディング:
1 select 'SSZ'+(RIGHT(10000000001 + ISNULL(RIGHT(MAX(MaterialCode),4),0),4)) as A from H6_MaterialFab where MaterialCode like 'SSZ%'

自動生成日:
SELECT 'CFR'+
DATENAME(YY, getdate()) +
DATENAME(MM, GETDATE()) +
(RIGHT(10000000001 + ISNULL(RIGHT(MAX(BillCode),3),0),3)) as A
FROM H6_StockMaterialAccBill
where DATENAME(YY, getdate()) + DATENAME(MM, getdate()) = substring(BillCode, 7, 6)
SELECT 'FMD' + 
'GLY' 
+ convert(char(8),GETDATE(),112) 
--+ DATENAME(YY,getdate())
-- + DATENAME(MM,GETDATE())
 + (RIGHT(10000000001 + ISNULL(MAX(RIGHT(Code,3)),0),3)) 
 as A FROM Financial_PayApplyFabBill  
 --where DATENAME(YY, getdate()) + DATENAME(MM, getdate()) = substring(Code, 7, 6) 

ランダム生成時間:(カーソル)
 declare cur cursor read_only for select PersonnelCode from KA_Personnel  
declare @PersonnelCode varchar(40)  o
pen cur  fetch next from cur into @PersonnelCode  while (@@fetch_status =0) 
begin insert into KA_Result([PersonnelCode] ,[ResultDateTime],[MorningDateTime1],[MorningDateTime2],[AfternoonDateTime1] ,[AfternoonDateTime2] ,[EveningDateTime1] ,[EveningDateTime2]) 
select @PersonnelCode, '{0}', CONVERT(time(0),dateadd(Second,Convert(int,CEILING(RAND()*1200)),'07:25:00')), 
CONVERT(time(0),dateadd(Second,Convert(int,CEILING(RAND()*1200)),'11:25:00')), 
CONVERT(time(0),dateadd(Second,Convert(int,CEILING(RAND()*1200)),'12:55:00')), 
CONVERT(time(0),dateadd(Second,Convert(int,RAND()*1200),'16:55:00')), 
CONVERT(time(0),dateadd(Second,Convert(int,RAND()*1200),'17:55:00')), 
CONVERT(time(0),dateadd(Second,Convert(int,RAND()*1200),'20:55:00'))  
 fetch next from cur into @PersonnelCode end close cur deallocate cur 

転載先:https://www.cnblogs.com/songjiali/archive/2011/11/14/2248702.html