Skip to content

sqlserver生成银行卡号

web240 edited this page Sep 23, 2016 · 2 revisions
select floor(rand()*100000000) ---生成的数是这样的:12.0  
select cast(floor(rand()*100000000) as int) ---生成的数是这样的:12  
select ceiling(rand() * 100000000) ---生成的数是这样的:12.0  
select cast(ceiling(rand() * 100000000) as int) ---生成的数是这样的:12  

select substring('HelloWorld!', 6, 6)   /* 结果:World */
select left('HelloWorld!', 5)           /* 结果:Hello */
select right('HelloWorld!', 6)          /* 结果:oWorld */

DROP PROCEDURE getrandnum
alter procedure getrandnum(@str nvarchar(7))
AS
declare @a nvarchar(50)
DECLARE @result NVARCHAR(50)
DECLARE @i INT
set @a=@str+CONVERT(NVARCHAR(8),CONVERT(int,CEILING(RAND()*100000000)))
SET @i=CEILING(LEN(@a)/4)
SET @result=SUBSTRING(@a,1,4)+' '+SUBSTRING(@a,5,4)+' '+SUBSTRING(@a,9,4)+' '+SUBSTRING(@a,13,4)
PRINT @a
PRINT @i
PRINT @result

EXEC getrandnum @str='1234567'


if exists (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[myProc]'))
   DROP PROCEDURE myProc
GO

CREATE PROCEDURE myProc 
	@inparam nvarchar(5),
	@outparam int OUTPUT

AS
SELECT Color, ListPrice 
FROM Production.Product WHERE Size > @inparam
SELECT @outparam = 100

IF  (@outparam > 0)
	RETURN 999
ELSE
	RETURN 888
GO
Clone this wiki locally