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

¶¯Ì¬Ö´ÐÐsqlÓï¾äµÄÎÊÌâ

declare @sql varchar(300),@lastqty decimal(18,3),@lastprice decimal(18,3),@month varchar(2)--Õâ¸öÊǶ¯Ì¬Ô·Ý
set @sql='select @lastqty = Stock'+@month +',@lastprice = Price'+@month+' from YMStock where matcode='Z0001''
-- select @lastqty=Stock10,@lastprice= Price10 from YMStock where matcode='Z0001'
--ÒòΪ
exec (@sql)
select @lastqty,@lastprice

--ÌáʾMust declare the variable '@lastqty'.
ÎÒÓ¦¸ÃÔõÑùдÈÃÄÄÁ½¸ö±äÁ¿ÓÐÖµ³öÀ´
»¹ÊÇÒªÓö¯Ì¬Óï¾ä°É

SQL code:
declare @sql varchar(300),@lastqty decimal(18,3),@lastprice decimal(18,3),@month varchar(2)--Õâ¸öÊǶ¯Ì¬Ô·Ý
set @sql='select @lastqty = Stock'+@month +',@lastprice = Price'+@month+' from YMStock where matcode='Z0001''
-- select @lastqty=Stock10,@lastprice= Price10 from YMStock where matcode='Z0001'
--ÒòΪ
exec ('DECLARE @lastqty decimal(18,3);'+@sql+';SELECT @lastqty')


ÓÃsp_executesql

SQL code:

Óï·¨²»¶Ô



¿´Ò»Ï EXEC sp_executesql

ÒýÓÃ
SQL codedeclare@sqlvarchar(300),@lastqtydecimal(18,3),@lastpricedecimal(18,3),@monthvarchar(2)--Õâ¸öÊǶ¯Ì¬Ô·Ýset@sql='select @lastqty = Stock'+@month+',@las


Ïà¹ØÎÊ´ð£º

csvÎļþת»»³Ésqlµ¼Èëµ½Êý¾Ý¿â£¬Ã»ÓÐÊý¾ÝΪºÎ£¿

Ö´ÐеÄ˳Ðò£º
1£©Îļþä¯ÀÀ¿ò£¨Ñ¡ÔñÎļþʹÓã©
Ñ¡ÔñºÃÎļþºó
µã»÷Ò»¸öµ¼Èë°´Å¥µÄʱºò £¬°ÑÉÏÃæÉÏ´«¿òÀïµÄcsvÎļþÒÔÒ»¸öIDΪÎļþÃû£¬ÉÏ´«µ½**/**Îļþ¼ÐÏÂ
2£©¶ÁÈ¡Õâ¸öÎļþ¼ÐϵÄcsvµÄÎļþ£¬×ª»»³Ésql
3 ......

sqlÓï¾ä¶à±í¶à×ֶβéѯ - MS-SQL Server / »ù´¡Àà

ÎÒÓжà¸ö±íA B C ½á¹¹ÊÇÒ»ÑùµÄ£¬¶¼ÓÐ2¸ö×Ö¶ÎnameºÍcontent,ÎÒÒªËÑË÷ËùÒÔ±íËùÓÐ×Ö¶ÎÖаüº¬¡°Öйú¡±µÄÄÚÈÝ Õâ¸öSQLÓï¾äÔõôд 

ÈçºÎ½«¶à¸ö±íµÄ²éѯ½á¹ûÁ¬³ÉÒ»¸ö±í Õâ¸öSQLÓï¾äÔõôд ±íµÄ½á¹¹ÊÇÒ»ÑùµÄ
ÀýÈç£ ......

´ÓORACLEµ½DB2µÄSQLÓï¾äÎÊÌâ

ÏÖÔÚÓÐÒ»ORACLEÖеÄSQLÓï¾ä£¬ÐèÒªÒÆÖ²µ½DB2ÖУ¬ÇëÎʸÃSQL¸ÄÈçºÎд
ORACLEÖУº
select floor(months_between(date1,date2)) from A  
date1,date2·Ö±ðΪ±íÖеÄÁ½¸ö×Ö¶Î £¬¶¼ÎªÈÕÆÚÐÍ 
DB2ÖÐÈçºÎʹÓÃÐ ......

sql ½ØÈ¡×Ö·û´®

ÎÒÒªµÃµ½Ò»¸ö×Ö·û´®È磺
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
¾ÍÊÇÒªµÃµ½|||ºóÃæµÄ×Ö·û´®£¬ÓÐʲôº¯ÊýÂð£¿ÔõôÓÃÄØ£¿Ð»Ð»£¡
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ