CREATE PROCEDURE [NEWTRAVEL].[usp_SelectHOTELsDynamic]
@WhereCondition nvarchar(500),
@OrderByExpression nvarchar(250) = NULL
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
DECLARE @SQL nvarchar(3250)
SET @SQL = '
SELECT
[HOTELCODE],
[LANGUAGECODE],
[BUSINESSCIRCLE],
[EXECUTIVECIRCLE],
[HLEVEL],
[ADDRESS],
[ZIPCODE],
[PHONE],
[FAX],
[ORDERPHONE],
[ORDERFAX],
[WEBSITE],
[EMAIL],
[ABOUTROOMFACILITY], [ID]
FROM
[NEWTRAVEL].[HOTEL]
WHERe
' + @WhereCondition
IF @OrderByExpression IS NOT NULL AND LEN(@OrderByExpression) > 0
BEGIN
SET @SQL = @SQL + '
ORDER BY
' + @OrderByExpression
END
EXEC sp_executesql @SQL