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 emp_no,emp_name,dept,title
from employee
where emp_name'Ó÷×ÔÇ¿' and dept in
(select dept from employee
where emp_name='Ó÷×ÔÇ¿')
--3¡¢°´²¿ÃŽøÐлã×Ü£¬Í³¼ÆÃ¿¸ö²¿ÃŵÄ×ܹ¤×Ê
select dept,sum(salary)
from employee
group by dept
--4¡¢²éÕÒÉÌÆ·Ãû³ÆÎª14´çÏÔʾÆ÷ÉÌÆ·µÄÏúÊÛÇé¿ö£¬ÏÔʾ¸ÃÉÌÆ·µÄ±àºÅ¡¢ÏúÊÛÊýÁ¿¡¢µ¥¼ÛºÍ½ð¶î
select a.prod_id,qty,unit_price,unit_price*qty totprice
from sale_item a,product b
where a.prod_id=b.prod_id and prod_name='14´çÏÔʾÆ÷'
--5¡¢ÔÚÏúÊÛÃ÷ϸ±íÖа´²úÆ·±àºÅ½øÐлã×Ü£¬Í³¼ÆÃ¿ÖÖ²úÆ·µÄÏúÊÛÊýÁ¿ºÍ½ð¶î
select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
from sale_item
group by prod_id
--6¡¢Ê¹ÓÃconvertº¯Êý°´¿Í»§±àºÅͳ¼ÆÃ¿¸ö¿Í»§1996ÄêµÄ¶©µ¥×ܽð¶î
select cust_id,sum(tot_amt) totprice
from sales
where convert(char(4),order_date,120)='1996'
group by cust_id
--7¡¢²éÕÒÓÐÏúÊۼǼµÄ¿Í»§±àºÅ¡¢Ãû³ÆºÍ¶©µ¥×ܶî
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id
group by a.cust_id,cust_name
--8¡¢²éÕÒÔÚ1997ÄêÖÐÓÐÏúÊۼǼµÄ¿Í»§±àºÅ¡¢Ãû³ÆºÍ¶©µ¥×ܶî
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'
group by a.cust_id,cust_name
--9¡¢²éÕÒÒ»´ÎÏúÊÛ×î´óµÄÏúÊۼǼ
select order_no,cust_id,sale_id,tot_amt
from sales
where tot_amt=
(select max(tot_amt)
from sales)
--10¡¢²éÕÒÖÁÉÙÓÐ3´ÎÏúÊÛµÄÒµÎñÔ±Ãûµ¥ºÍÏúÊÛÈÕÆÚ
select emp_name,order_date
from employee a,sales b
where emp_no=sale_id and a.emp_no in
(select sale_id
from sales
group by sale_id
having count(*)>=3)
order by emp_name
--11¡¢ÓôæÔÚÁ¿´Ê²éÕÒûÓж©»õ¼Ç¼µÄ¿Í»§Ãû³Æ
select cust_name
from customer a
where not exists
(select *
from sales b
where a.
Ïà¹ØÎĵµ£º
1¡¢ÔÚÁíһ̨»úÆ÷ÉϽ¨Á¢¶ÀÁ¢µÄÊý¾Ý¿â·þÎñÆ÷£¬×÷ΪÁ´½ÓÄ¿±ê
2¡¢±¾µØÊý¾Ý¿â·þÎñÆ÷ÉÏÌí¼Ó“Á´½Ó·þÎñÆ÷”£º
Ãû×Ö£ºËæ±ãȡһ¸öÃû×Ö
·þÎñÆ÷ÀàÐÍ£ºÑ¡ÔñÊý¾ÝÔ´£ºMicrosoft OLE DB Provider for SQL Server
Êý¾ÝÔ´£ºÐ´±ðÃû£¨ÔÚ¿Í»§¶ËÍøÂçʵÓù¤¾ßÖÐÉèÖã©
Ñ¡ÖÐRPCºÍRPCÊä³ö ......
create PROCEDURE [dbo].[P_PageTest]
@SQL Nvarchar(max), --SQLÓï¾ä²»°üÀ¨ÅÅÐò
@CurPage int, --µ±Ç°Ò³
@PageRows int, --Ò³Ãæ³ß´ç
@Order Nvarchar(20), --ÅÅÐò×Ö¶Î
@OrderType Nvarchar( ......
C#Á¬½ÓSQL ServerµÄSqlConnectionµÄ×Ö·û´®£¬Ðí¶à¶¼ÊDz»ÄÜÁ¬½ÓµÄ¡£ÏÖÔÚ¸øÒ»¸öÄÜÁ¬½ÓµÄ£º
using System.Data.SqlClient;
public class sqlServerConnection {
//
public static void Main() {
//ÏÂÃæ¾ÍÊDZê×¼µÄÁ¬½Ó£¬×¢ÒâSERVERÊÇÎҵļÆËã»úÃû¡£SQLEXPRESSÊÇÊý¾Ý¿âʵÀý¡£SSPI±íʾʹÓÃWindowsµÇ½µÄÕÊ»§¡£masterÊÇÒªÁ¬½Óµ ......
ÓÃSQLÉú³ÉÁ÷Ë®ºÅ
ת£ºÎ¤½ÌÎ ·¢±íÓÚ2010Äê02ÔÂ03ÈÕ 09:38 ÔĶÁ(4) ÆÀÂÛ(0)
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_FillNumberWithZero]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_FillNumberWithZero]
GO
if exists ( ......
½üÆÚÒò¹¤×÷ÐèÒª£¬Ï£Íû±È½ÏÈ«ÃæµÄ×ܽáÏÂ
SQL SERVER
Êý¾Ý¿âÐÔÄÜÓÅ»¯Ïà¹ØµÄ×¢ÒâÊÂÏÔÚÍøÉÏËÑË÷ÁËÒ»ÏÂ
,
·¢ÏֺܶàÎÄÕÂ
,
ÓеͼÁгöÁËÉϰÙÌõ
,
µ«ÊÇ×Ðϸ¿´·¢ÏÖ£¬ÓкܶàËÆÊǶø·Ç»òÕß¹ýʱ
(
¿ÉÄܶÔ
SQL SERVER6.5
ÒÔǰµÄ°æ±¾»òÕß
ORACLE
ÊÇÊÊÓõÄ
)
µÄÐÅÏ¢£¬Ö»ºÃ×Ô¼º¸ù¾ÝÒÔǰµÄ¾ÑéºÍ²âÊÔ½á¹û½øÐÐ×ܽáÁË¡£
ÎÒ ......