sql ¼òµ¥Óαê
ÔÚ´æ´¢¹ý³Ì»ò´¥·¢Æ÷ÖÐʹÓà Transact-SQL ÓαêµÄµäÐ͹ý³ÌΪ£º
ÉùÃ÷ Transact-SQL ±äÁ¿°üº¬Óα귵»ØµÄÊý¾Ý¡£ÎªÃ¿¸ö½á¹û¼¯ÁÐÉùÃ÷Ò»¸ö±äÁ¿¡£ÉùÃ÷×ã¹»´óµÄ±äÁ¿À´±£´æÁзµ»ØµÄÖµ£¬²¢ÉùÃ÷±äÁ¿µÄÀàÐÍΪ¿É´ÓÁÐÊý¾ÝÀàÐÍÒþʽת»»µÃµ½µÄÊý¾ÝÀàÐÍ¡£
ʹÓà DECLARE CURSOR Óï¾ä½« Transact-SQL ÓαêÓë SELECT Óï¾äÏà¹ØÁª¡£ÁíÍ⣬DECLARE CURSOR Óï¾ä»¹¶¨ÒåÓαêµÄÌØÐÔ£¬ÀýÈçÓαêÃû³ÆÒÔ¼°ÓαêÊÇÖ»¶Á»¹ÊÇÖ»½ø¡£
ʹÓà OPEN Óï¾äÖ´ÐÐ SELECT Óï¾ä²¢Ìî³äÓαꡣ
ʹÓà FETCH INTO Óï¾äÌáÈ¡µ¥¸öÐУ¬²¢½«Ã¿ÁÐÖеÄÊý¾ÝÒÆÖÁÖ¸¶¨µÄ±äÁ¿ÖС£È»ºó£¬ÆäËû Transact-SQL Óï¾ä¿ÉÒÔÒýÓÃÄÇЩ±äÁ¿À´·ÃÎÊÌáÈ¡µÄÊý¾ÝÖµ¡£Transact-SQL Óα겻֧³ÖÌáÈ¡Ðп顣
ʹÓà CLOSE Óï¾ä½áÊøÓαêµÄʹÓ᣹رÕÓαê¿ÉÒÔÊÍ·ÅijЩ×ÊÔ´£¬ÀýÈçÓαê½á¹û¼¯¼°Æä¶Ôµ±Ç°ÐеÄËø¶¨£¬µ«Èç¹ûÖØз¢³öÒ»¸ö OPEN Óï¾ä£¬Ôò¸ÃÓαê½á¹¹ÈÔ¿ÉÓÃÓÚ´¦Àí¡£ÓÉÓÚÓαêÈÔÈ»´æÔÚ£¬´Ëʱ»¹²»ÄÜÖØÐÂʹÓøÃÓαêµÄÃû³Æ¡£DEALLOCATE Óï¾äÔòÍêÈ«ÊÍ·Å·ÖÅä¸øÓαêµÄ×ÊÔ´£¬°üÀ¨ÓαêÃû³Æ¡£ÊÍ·ÅÓαêºó£¬±ØÐëʹÓà DECLARE Óï¾äÀ´ÖØÐÂÉú³ÉÓαꡣ
Õª×Ô£ºms-help://MS.SQLCC.v9/MS.SQLSVR.v9.zh-CHS/udb9/html/a5f0904e-0171-44fa-b516-14c6dc91ccd0.htm
declare @value1 varchar(20);
declare @value2 varchar(20);
declare cursor_demo cursor for
select t1.id,t2.id from t1 left join t2 on t1.id=t2.id
open cursor_demo
FETCH NEXT from cursor_demo INTO @value1, @value2
WHILE @@FETCH_STATUS = 0
BEGIN
if(@value1=@value2)
begin
update t1 set [name]='goodtobad' where id=@value1
end
FETCH NEXT from cursor_demo INTO @value1, @value2
END
CLOSE cursor_demo
DEALLOCATE cursor_demo
GO
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
Private Sub CommandButton1_Click()
Worksheets("Sheet2").Select
Cells.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
'Çå³ýÔÚExcelÖеÄÊý¾Ý,È·±£µ¼ÈëÐÅÏ¢²»³öÏÖÓëÔExcelÊý¾Ý½øÐеþ¼Ó
Dim cnnConnect As Object
Dim rstR ......
ÓÐʱºò£¬ÔÚ¹¤×÷ÖлáÓöµ½½«Ò»¸öÊý¾Ý¿âÖбíµÄÊý¾Ýµ¼µ½ÁíÒ»¸öÊý¾Ý¿âµÄ±íÖУ¬µ«Êǹ¤¾ßÓÖûÓÐÌṩÕâÑùµÄ¹¦ÄÜ
ÏÂÃæÄÜͨ¹ýSQLÓï¾äÉú³ÉInsertÓï¾ä£¬ÔÙ²åÈëµ½ÁíÒ»¸öÊý¾Ý¿âÖС£
MSSQL:
SELECT 'INSERT INTO StatInfo(UserName,CardId,Address,WageCount,Pension)'+
' VALUES('''+a.UserName+''','''+a.CardId+''','''+a.Ad ......
--»ù´¡Á˽⣺
1) select distinct name from table --´ò¿ªÖظ´¼Ç¼µÄµ¥¸ö×Ö¶Î
2) select * from table where fid in(Select min(fid) from table group by name)--´ò¿ªÖظ´¼Ç¼µÄËùÓÐ×Ö¶ÎÖµ
3) select * from table where name in(select name from table group by name having count(name)=1)--´ò¿ªÖظ´ÈÎÒâ´ÎÊýµ ......
CREATE FUNCTION dbo.UF_GetInvoiceSerials( @bizCode VARCHAR(10))
RETURNS VARCHAR(100)
AS
BEGIN
DECLARE @ret AS VARCHAR(1000)
SELECT @ret=Coalesce(@ret + ', ','') +
CASE e.ID
  ......