SQLÖÐ ³£ÓõĴ¦Àí·½·¨
-- Ò»£º ´¦Àíδ²éµ½µÄ¿ÕÖµ
select
case when exists(select EndPrice from T_stock where BOMSN='0109')
then (select EndPrice from T_stock where BOMSN='0109')
else 0 end
--¶þ£º¸üÐÂ×Ö¶ÎÖµ
--strNum ÊýÁ¿
--strId ÐòºÅ
update T_buy_Pro set CompentNum=isnull(CompentNum,0)+'strNum' ,
Status= case when isnull(BuyNumber,0) > isnull(CompentNum,0)+ 'strNum'
then '²¿·ÖÊÕÁÏ' else 'È«²¿ÊÕÁÏ' end
where BuyProID='strId'
È¥µôСÊýµãÓÐЧÊý×ÖºóÃæµÄËùÓÐ0
decimalÀàÐÍ£¬Ð¡ÊýλÊýÊÇ6룬Èç¹û²åÈëµÄÊý¾ÝΪ2.5£¬Ôò¼ìË÷ʱÏÔʾΪ2.500000
select cast(2.500000 as real)
----------½¨Ò»個º¯數Íê³É-------------
Create Function trun(@i decimal(18,6))
returns varchar(30)
begin
declare @s varchar(30)
set @s=cast(@i as varchar(30))
while len(@s)>0
begin
if cast(substring(rtrim(@s),len(rtrim(@s))-1,1) as int)<>0
begin
set @s=substring(rtrim(@s),1,len(@s)-1)
break
end
set @s=substring(rtrim(@s),1,len(@s)-1)
end
return(@s)
end
----------------------------結Êøº¯數--------
Ïà¹ØÎĵµ£º
Ðл»ÁУº
--> Éú³É²âÊÔÊý¾Ý±í: [tb]
IF OBJECT_ID('[tb]') IS NOT NULL
DROP TABLE [tb]
GO
CREATE TABLE [tb] ([a] [int],[b] [int],[c] [int])
INSERT INTO [tb]
SELECT '3','9','5' UNION ALL
SELECT '5','2','7' UNION ALL
SELECT '6','3','8'
--SELECT * from [tb]
-->SQL²éѯÈçÏ ......
USE master
GO
DECLARE @dbname sysname
SET @dbname='TEST' --Õâ¸öÊÇҪɾ³ýµÄÊý¾Ý¿â¿âÃû
DECLARE @s NVARCHAR(1000)
DECLARE tb CURSOR local FOR
SELECT s='KILL '+CAST(spid AS NVARCHAR)&nbs ......
±¾ÎÄ´ÓÊý¾Ý¿âÉè¼Æ¡¢¿ª·¢¡¢DBA¹ÜÀíµÈËĸö·½ÃæÐðÊöÁËSQL2005ÓëSQL2000Á½¸ö°æ±¾¼äµÄ¸Ä½ø¡£
¡¡¡¡Ò»¡¢Êý¾Ý¿âÉè¼Æ·½Ãæ
¡¡
¡¡1¡¢×Ö¶ÎÀàÐÍ¡£
¡¡¡¡varchar(max)
varchar(max)ÀàÐ͵ÄÒýÈë´ó´óµÄÌá¸ßÁ˱à³ÌµÄЧÂÊ£¬¿ÉÒÔʹÓÃ×Ö·û´®º¯Êý¶ÔCLOBÀàÐͽøÐвÙ×÷£¬ÕâÊÇÒ»¸öÁÁµã¡£µ«ÊÇÕâ¾ÍÒý·¢Á˶Ôvarchar
ºÍcharЧÂÊÌÖÂÛµÄÀÏÎÊÌâ¡£µ½µ ......
½éÉÜGROUP BY ºÍ HAVING ×Ó¾äǰ£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý:¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
SELECT SUM(population) from bbc
ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéѯֻ·µ»ØÒ»¸ö½á¹û£¬¼´ËùÓйú¼ÒµÄ×ÜÈË¿ ......