Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¹ØÓÚSQL SERVER Êý¾Ý²ð·Ö

if object_id('tb') is not null drop table tb
go
create table tb([A] varchar(10),[B] int)
insert tb
select 'bcd',1 union all
select 'bcde',2 union all
select 'cd',3
go
¸öÈË·ÖÎöÕâµÀÌâµÄ˼·ÊÇ£º
ͨ¹ýSubstring() À´Ñ­»··Ö¸î B ÁÐϵÄ×Ö·û´®¡£¡£
--ÏëµÃµ½µÄ½á¹û£º
/**
a    b          
---- -----------
b    1
c    1
d    1
b    2
c    2
d    2
e    2
c    3
d    3
£¨ËùÓ°ÏìµÄÐÐÊýΪ 9 ÐУ©
**/
£¨1£©£ºselect
substring(a.A,b.number,1) as a,a.b
from tb a,
master..spt_values b
where b.type='P' and b.number>0
and b.number<len(a.a)
/**
a    b          
---- -----------
b    1
c    1
d    1
b    2
c    2
d    2
e    2
c    3
d    3
£¨ËùÓ°ÏìµÄÐÐÊýΪ 9 ÐУ©
**/
£¨2£©
SELECT TOP 100 ID=IDENTITY(INT,1,1) INTO #NUM from SYS.SYSCOLUMNS A,SYS.SYSCOLUMNS B
SELECT
    A.b,[VALUE]=SUBSTRING(A.a,B.ID,1)
from
    #TB A,#NUM B
WHERE
    b.id <=len(a.a)
/*
b          VALUE
----------- -----
1          b
1          c
1          d
2          b
2          c
2          d
2          e
3          c
3          d


Ïà¹ØÎĵµ£º

SQL»ù´¡

SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢É¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ ......

SQLʵÀý

--1¡¢²éÕÒÔ±¹¤µÄ±àºÅ¡¢ÐÕÃû¡¢²¿ÃźͳöÉúÈÕÆÚ£¬Èç¹û³öÉúÈÕÆÚΪ¿ÕÖµ£¬ÏÔʾÈÕÆÚ²»Ïê,²¢°´²¿ÃÅÅÅÐòÊä³ö,ÈÕÆÚ¸ñʽΪyyyy-mm-dd¡£
select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'ÈÕÆÚ²»Ïê') birthday
from employee
order by dept
--2¡¢²éÕÒÓëÓ÷×ÔÇ¿ÔÚͬһ¸öµ¥Î»µÄÔ±¹¤ÐÕÃû¡¢ÐԱ𡢲¿ÃźÍÖ°³Æ
select ......

±í½á¹¹ÐÅÏ¢²éѯ sql server 2005


--sql server 2005
-- 1. ±í½á¹¹ÐÅÏ¢²éѯ
-- ========================================================================
-- ±í½á¹¹ÐÅÏ¢²éѯ
-- ×Þ½¨ 2005.08(ÒýÓÃÇë±£Áô´ËÐÅÏ¢)
-- ========================================================================
SELECT
    TableName=CASE WHEN ......

SQLÖÐʹÓÃCONVERTת»»Ê±¼äÊä³ö¸ñʽ

SELECT CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
SELECT CONVERT(varchar(100), GETDATE(), 1): 05/16/06
SELECT CONVERT(varchar(100), GETDATE(), 2): 06.05.16
SELECT CONVERT(varchar(100), GETDATE(), 3): 16/05/06
SELECT CONVERT(varchar(100), GETDATE(), 4): 16.05.06
SELECT CONVERT(varch ......

SQL SERVER 2005 ¼ò½é


      SQL SERVER 2005 ¼ò½é
    Ò»Ö±ÒÔÀ´£¬T-SQL¶¼ÊÇÈÝÒ×ÉÏÊֵĽṹ»¯²éѯÓïÑÔ£¬Ëæ×ÅSQL ServerµÄ°æ±¾Ñݽø£¬³ýÁËÄÚ²¿¹¦ÄÜÔö¼Ó£¬
T-SQLÒ²´ó·ùÀ©ÔöÁËеIJéѯָÁî¡£ÀýÈ磺XQuery¡¢È¡µÃÅÅÃû˳ÐòµÄº¯Êý¡¢¼¯ºÏÔËËã´îÅäOVERÔËËã·û¡¢TOPÔËËã·û¿ÉÒÔ´îÅä±äÁ¿»ò×Ó²éѯ£¬ÒÔ¼°Í ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ