悬赏园豆:10
[已解决问题]
解决于 2008-05-19 00:18
<P>字符串拼接的存储过程/视图/函数 效率问题!</P>
<P>如USE [PMS_HZTEST]<BR><BR>ALTER PROCEDURE [dbo].[FIN_CurrentDepositLedger_Select]<BR>(<BR> @PID BIGINT,<BR> @LGID BIGINT = NULL<BR>)<BR>AS<BR>SET NOCOUNT OFF;<BR>DECLARE @SQL_Statement NVARCHAR(3000);</P>
<P>BEGIN</P>
<P> IF @LGID IS NULL<BR> BEGIN<BR> SET @LGID=dbo.dpk_FD_DefaultLanguage();<BR> END<BR></P>
<P> SET @SQL_Statement = '<BR>SELECT DISTINCT CASE WHEN z.stayBKTID=2<BR> THEN ''G''+IsNull(z.stayResvNo,'''')<BR> ELSE IsNull(z.stayResvNo,'''')<BR> END AS RESV#,z.stayHDID,<BR> z.BusinessDate AS RESV_DATE,<BR> dbo.uf_RPT_GetGuestName(z.stayBKTID,z.stayGuestPFID,z.stayDelegateFamilyName,z.stayDelegateGivenName, b.pfFamilyName,b.pfGivenName,c.hdGroupName) AS GUSET_NAME,<BR> stayArrivalDate AS ARRIVAL,<BR> [dbo].[uf_RPT_GetNoOfNTS](z.stayArrivalDate, z.stayDepartureDate) AS #NTS,<BR> ISNULL(e.rtCode,'''') AS RM_TYPE,<BR> dbo.uf_RPT_GetNoOfRoom_CurDepositLedger(z.PID,z.stayBKTID,e.rtROID,d.roomRTID,e.rtIsAffectAvail,z.stayShareWithSTID,z.stayHDID) AS #ROOM,<BR> dbo.uf_RPT_GetRMRate(z.pid,z.stayID,'+CAST(@LGID AS NVARCHAR)+','''+CONVERT(NVARCHAR(20),@BusinessDate,111)+''') AS RM_RATE,<BR> [dbo].[uf_RPT_GetTotalRoomCharges](z.PID,z.StayID,z.stayBKTID,z.stayHDID) AS TOTAL_ROOM_CHARGES,<BR> IsNull(a.dltAmt,0) AS DEPOSIT_RECEIVED,<BR> [dbo].[uf_RPT_Get_DiscountAmt](z.PID,z.StayID,z.stayBKTID,z.stayHDID) AS DISCOUNT_DEDUCTED,<BR> dbo.uf_RPT_GetHCV_dltID(z.PID,z.stayid) AS HCV#,<BR> a.BusinessDate AS DEPOSIT_DATE,<BR> ISNULL(g.plDesc,'''') AS PNAME,<BR> ISNULL(h.pCode,'''') AS PID,<BR> a.dltid<BR>FROM TXN_Stay z(NOLOCK)<BR> INNER JOIN TXN_DepositLedgerTxn a(NOLOCK) ON (z.PID=a.PID AND z.STAYID=a.dltSTAYID)<BR> LEFT JOIN Resv_Profile b(NOLOCK) ON (b.PFID=z.stayGuestPFID AND b.PFID>0)<BR> INNER JOIN TXN_Header c(NOLOCK) ON (c.HDID = z.stayHDID AND c.PID=z.PID)<BR> INNER JOIN Txn_Room d(NOLOCK) ON (z.stayROOMID=d.ROOMID AND d.PID=z.PID)<BR> LEFT JOIN FO_RoomType e(NOLOCK) ON (e.RTID=d.roomRTID AND e.PID=d.PID)<BR> INNER JOIN FO_Property h(NOLOCK) ON (h.PID=z.PID)<BR> LEFT JOIN vw_Property_Local g(NOLOCK) ON (g.PID=h.PID AND g.LGID='+CAST(@LGID AS NVARCHAR)+' AND g.IsDeleted=0)<BR>WHERE STAYID>0 AND z.stayInhouseSTID=102001 AND a.dltSTID IN (112001, 112004, 112009) AND a.dltType=1 ';</P>
<P> PRINT @SQL_Statement;<BR> <BR> print len(@SQL_Statement);<BR> <BR> EXECUTE (@SQL_Statement);</P>
<P> RETURN 0;<BR>END<BR></P>
<P>------------------------------------------------------------------</P>
<P>字符串拼接的存储过程中->函数多点好? 还是视图多点好? 还有写子查询?</P>
<P>在性能上那个好一点?</P>
<P><BR> </P>
<P> </P>
IamV
|
初学一级
|
园豆:
180
提问于:2008-05-05 01:44