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

SQLÃæÊÔÌ⣨תÔØ£©

SQLÃæÊÔÌ⣨1£©
create table testtable1
(
id int IDENTITY,
department varchar(12)
)
select * from testtable1
insert into testtable1 values('Éè¼Æ')
insert into testtable1 values('Êг¡')
insert into testtable1 values('ÊÛºó')
/*
½á¹û
id department
1   Éè¼Æ
2   Êг¡
3   ÊÛºó
*/
create table testtable2
(
id int IDENTITY,
dptID int,
name varchar(12)
)
insert into testtable2 values(1,'ÕÅÈý')
insert into testtable2 values(1,'ÀîËÄ')
insert into testtable2 values(2,'ÍõÎå')
insert into testtable2 values(3,'ÅíÁù')
insert into testtable2 values(4,'³ÂÆß')
/*
ÓÃÒ»ÌõSQLÓï¾ä£¬ÔõôÏÔʾÈçϽá¹û
id dptID department name
1   1      Éè¼Æ        ÕÅÈý
2   1      Éè¼Æ        ÀîËÄ
3   2      Êг¡        ÍõÎå
4   3      ÊÛºó        ÅíÁù
5   4      ºÚÈË        ³ÂÆß
*/
´ð°¸£º
SELECT testtable2.* , ISNULL(department,'ºÚÈË')
from testtable1 right join testtable2 on testtable2.dptID = testtable1.ID
Ò²×ö³öÀ´Á˿ɱÈÕâ·½·¨ÉÔ¸´ÔÓ¡£
sqlÃæÊÔÌ⣨2£©
ÓбíA£¬½á¹¹ÈçÏ£º
A: p_ID p_Num s_id
1 10 01
1 12 02
2 8 01
3 11 01
3 8 03
ÆäÖУºp_IDΪ²úÆ·ID£¬p_NumΪ²úÆ·¿â´æÁ¿£¬s_idΪ²Ö¿âID¡£ÇëÓÃSQLÓï¾äʵÏÖ½«ÉϱíÖеÄÊý¾ÝºÏ²¢£¬ºÏ²¢ºóµÄÊý¾ÝΪ£º
p_ID s1_id s2_id s3_id
1 10 12 0
2 8 0 0
3 11 0 8
ÆäÖУºs1_idΪ²Ö¿â1µÄ¿â´æÁ¿£¬s2_idΪ²Ö¿â2µÄ¿â´æÁ¿£¬s3_idΪ²Ö¿â3µÄ¿â´æÁ¿¡£Èç¹û¸Ã²úÆ·ÔÚij²Ö¿âÖÐÎÞ¿â´æÁ¿£¬ÄÇô¾ÍÊÇ0´úÌæ¡£
½á¹û£º
select p_id ,
sum(case when s_id=1 then p_num else 0 end) as s1_id
,sum(case when s_id=2 then p_num else 0 end) as s2_id
,sum(case when s_id=3 then p_num else 0 end) as s3_id
from myPro group by p_id
SQLÃæÊÔÌ⣨3£©
1£®´¥·¢Æ÷µÄ×÷Óã¿
  ´ð£º´¥·¢Æ÷ÊÇÒ»ÖÐÌØÊâµÄ´æ´


Ïà¹ØÎĵµ£º

sql server È«ÎļìË÷£¬¹¦ÄܽéÉÜ£¬Ó¦ÓÃÌصã×ܽᡣ

ÔÚÒ»¸öÊý¾Ý±íÀÓÐ3¸ö×ֶΣ¬ÈçÏ£º
ID           ×Ô¶¯Ôö¼Ó£¬Òѽ¨Ë÷Òý
TITLE      nvarchar(255)
CONTENT ntext(16)
¶Ôtitle×ֶνøÐГlike”²éѯ£¬ËٶȻ¹ÐС£µ«ÊÇÒª¶Ôcontent×ֶΣ¬½øÐГlike”²éѯ£¬ËٶȺÜÂý£¬²»¿É ......

VC++µÄADOÁ¬½ÓSQL Server²½Öè

 1£ºSQL  ServerÊý¾Ý¿âÅäÖÃ
 
 
 
¿ªÆô·þÎñÆ÷
 
 
ÍÐÅÌÏÔʾ·þÎñÆ÷Æô¶¯
 
 
 
2:ÔÚStaAfx.h ÖÐÌí¼ÓÈçÏ´úÂë
#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace      rename("EOF","adoEOF")rena ......

SQLÃüÁî´óÈ«

[code=SQL][/code]
--Óï ¾ä ¹¦ ÄÜ 
--Êý¾Ý²Ù×÷ 
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁР
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐР
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐР
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå 
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í 
DROP TABLE --´ÓÊý¾Ý¿âÖÐɾ ......

SQL ServerÖÐDateTime¸ñʽת»»

SQLʹÓÃconvertÀ´È¡µÃdatetimeÈÕÆÚÊý¾Ý£¬ÒÔÏÂʵÀý°üº¬¸÷ÖÖÈÕÆÚ¸ñʽµÄת»»,
¿ÉÒÔͨ¹ý²éѯÓï¾ä¼°²éѯ½á¹ûÀ´ÏÔʾ²»Í¬µÄ¸ñʽ£¬Èç¹ûÊÇDate¸ñʽҲ¿ÉÒÔÓãº
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 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ