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

¶¯Ì¬sqlÓï¾ä»ù±¾Óï·¨

1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃExecÖ´ÐÐ
      Àý:      Select * from tableName
                Exec('select * from tableName')
                Exec sp_executesql N'select * from tableName'    -- Çë×¢Òâ×Ö·û´®Ç°Ò»¶¨Òª¼ÓN
 
2:×Ö¶ÎÃû£¬±íÃû£¬Êý¾Ý¿âÃûÖ®Àà×÷Ϊ±äÁ¿Ê±£¬±ØÐëÓö¯Ì¬SQL
 
    ´íÎó:        declare @fname varchar(20)
                set @fname = 'FiledName'
                Select @fname from tableName              -- ´íÎó,²»»áÌáʾ´íÎ󣬵«½á¹ûΪ¹Ì¶¨ÖµFiledName,²¢·ÇËùÒª¡£
    ÕýÈ·:      Exec('select ' + @fname + ' from tableName')     -- Çë×¢Òâ¼ÓºÅÇ°ºóµÄµ¥ÒýºÅµÄ±ßÉϼӿոñ
 
    µ±È»½«×Ö·û´®¸Ä³É±äÁ¿µÄÐÎʽҲ¿É
                declare @fname varchar(20)
                set @fname = 'FiledName' --ÉèÖÃ×Ö¶ÎÃû
 
                declare @s varchar(1000)
                set @s = 'select ' + @fname + ' from tableName'
                Exec(@s)                -- ³É¹¦
     


Ïà¹ØÎĵµ£º

fastreport´òÓ¡´úÂë¼°SQLºÏ²¢×ֶεÄÓï¾ä

 procedure Tform1.Button5Click(Sender: TObject);
var
  p:pointer;
  FrfStr:string;
begin
  inherited;
  Screen.Cursor:=MYCURSORWAITHAND;
  with cdsPrint do
  begin
    Active:=false;
    //Õâ¸öSQLÓÃÓÚ½«remarkÖеļǼºÏ²¢µ½Ò»Æ ......

SQL ¿ØÖÆÁ÷³Ì

Transact-SQL ÌṩÁË(BEGIN...END¡¢BREAK¡¢GOTO¡¢CONTINUE¡¢IF...ELSE¡¢WHILE¡¢RETURN¡¢WAITFOR)¿ØÖÆÁ÷¹Ø¼ü×Ö£¬ÓÃÓÚ¿ØÖÆ Transact-SQL Óï¾ä¡¢Óï¾ä¿é¡¢Óû§¶¨Ò庯ÊýÒÔ¼°´æ´¢¹ý³ÌµÄÖ´ÐÐÁ÷¡£ ²»Ê¹ÓÿØÖÆÁ÷ÓïÑÔ£¬Ôò¸÷ Transact-SQL Óï¾ä°´Æä³öÏÖµÄ˳Ðò·Ö±ðÖ´ÐС£¿ØÖÆÁ÷ÓïÑÔʹÓÃÓë³ÌÐòÉè¼ÆÏàËƵĹ¹ÔìʹÓï¾äµÃÒÔ»¥ÏàÁ¬½Ó¡¢¹ØÁªºÍ ......

sql ½»²æ±í

½»²æ±íÓï¾äµÄʵÏÖ:
¡¡¡¡ÓÃÓÚ:½»²æ±íµÄÁÐÊýÊÇÈ·¶¨µÄ
¡¡¡¡select name,sum(case subject when 'Êýѧ' then source else 0 end) as 'Êýѧ',
¡¡¡¡sum(case subject when 'Ó¢Óï' then source else 0 end) as 'Ó¢Óï',
¡¡¡¡sum(case subject when 'ÓïÎÄ' then source else 0 end) as 'ÓïÎÄ'
¡¡¡¡from test
¡¡¡¡group by name ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ