SQLÈçºÎÓÅ»¯ÎÊÌâ - MS-SQL Server / ÒÉÄÑÎÊÌâ
½ñÌì×öÁËÒ»¸ö´æ´¢¹ý³Ì »·¾³ÊÇSQL2000Êý¾Ý¿â
´óÖÂÈçÏÂ
½¨Á¢ÁÙʱ±í
¶¨ÒåÔ±¹¤Óαê
Ñ»·Ô±¹¤£¨ÊôÓÚ1¸ö¹«Ë¾)
¶¨Ò幫˾¹¤×ÊÏîÄ¿Óαê
Ñ»·¸Ã¹«Ë¾¹¤×ÊÏîÄ¿(ÓÐ50¸ö×óÓÒ¹¤×ÊÏîÄ¿)
£¨ÓÐЩ¿ÉÒÔÖ±½Ó´Ó¹¤×ʱíÀïÃæÖ±½ÓÈ¡³öÀ´ ±ÈÈçÌõ¼þÊǹ¤×ÊÏîÄ¿±àºÅ=2
µ«ÊÇÓÐЩ²»ÄÜÖ±½ÓÈ¡ ±ÈÈ繤×ÊÏîÄ¿±àºÅ2+ ¹¤×ʱàºÅ3µÈµÈ
¼ÆËãÁ¿¿ÉÄܱȽϴó ÕâÀïµÄSQL¶¼ÊǶ¯Ì¬Éú³É³öÀ´µÄ£©
ÿ´ÎÓÃexec sp_executesql ¼ÆËã½á¹û
½áÊøÑ»·¸Ã¹«Ë¾
Ïà¹ØÎÊ´ð£º
´ó¼Ò°ïæ¿´¿´Õâ2¸ösqlÓï¾äÄĸö²éѯµÄËٶȸü¿ìµã¡£Ð»Ð»°ïæ¡£±È½Ï׿±¡£ÔÚ×öÐÔÄܲâÊÔ¡£
select * from
±íA LEFT OUTER JOIN ±íB ON (±íA.id || ' ' =±íB.id) ,±íC , ±íD, ±íE
WhereÆäËûÌõ¼þ
select * ......
ÎÒÓжà¸ö±íA B C ½á¹¹ÊÇÒ»ÑùµÄ£¬¶¼ÓÐ2¸ö×Ö¶ÎnameºÍcontent,ÎÒÒªËÑË÷ËùÒÔ±íËùÓÐ×Ö¶ÎÖаüº¬¡°Öйú¡±µÄÄÚÈÝ Õâ¸öSQLÓï¾äÔõôд
ÈçºÎ½«¶à¸ö±íµÄ²éѯ½á¹ûÁ¬³ÉÒ»¸ö±í Õâ¸öSQLÓï¾äÔõôд ±íµÄ½á¹¹ÊÇÒ»ÑùµÄ
ÀýÈç£ ......
±íÈçÏÂ
½ÌÊÒID ×ùλÊý ¿ªÊ¼Ê±¼ä ½áÊøʱ¼ä 2009Äê1ÔÂ1ÈÕ 2009Äê1ÔÂ2ÈÕ 2009Äê1ÔÂ3ÈÕ
101 50 08£º00 08£º30 30 40 50
101 50 09£º00 ......
ÎÒµÄTblworkbill±íµÄÊý¾ÝÈçÏÂ:
id workbillno ..................
1 1
2 6
3 a1
4 c2
5 2
6 aa
7 ......
CREATE PROCEDURE [selectvipcompany]
@username varchar(50),
@companyname varchar(50),
@endtime varchar(1)
AS
declare @sql varchar(1000)
set @sql=''
if (@username<>null and @username ......