I know this is not possible, but is there something that works? Basically I want the where statement to be dynamic, allowing me to pass it any string that it can find.
Declare @search varchar(80) set @search = 'RegionID' Select * from TBL_TripDetails Where @search = '1'
Thank you for your responses. After reading several documents, I decided to use several select statements instead of using dynamic sql. thank!
declare @sql nvarchar(max); set @sql = N'select * from table where ' + quotename(@search) + N'=''1'''; exec sp_executesql @sql;
See Curse and blessings of dynamic SQL
This is indeed possible, although he was often frowned at. Take a look at sp_executesql
Declare @search varchar(80) set @search = 'RegionID' declare @query varchar(max) set @query = "Select * from TBL_TripDetails Where " + @search + " = '1'" exec @query
DECLARE @search VARCHAR(80) DECLARE @SQL VARCHAR(8000) SET @search = 'RegionID' SET @SQL = 'SELECT * FROM TBL_TripDetails WHERE ' + @search + ' = 1' EXEC @SQL
. SQL SQL-.
: " , ". , 1, .
, , Dynamic SQL. / (, RegionID , , ), .
DECLARE @RegionID AS VARCHAR(1); SELECT * FROM TABLE WHERE (@RegionID Is Null OR @RegionID = '' OR RegionID = @RegionID);
, @RegionID NULL, .
Source: https://habr.com/ru/post/1758421/More articles:Window transparency in WPF and Winforms - opacityТип вложенной структуры в классе шаблона - c++Using Blackberry to Access Oracle Database? - javaThe best way to get maven dependencies is maven-2https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1758420/what-is-the-fastest-way-to-convert-all-pk-and-fk-guid-columns-and-relationships-to-int&usg=ALkJrhhvgcdD0LI9kV79OGFErhHyFzDP4AИспользуйте сервисную шину Rhino на веб-сайте ASP.NET с помощью Ninject - dependency-injectionHow to trigger a debug break in firebug - debuggingDetermining the background color of alternating rows of TreeView based on visibility - wpfA simple CMS to create a presentation website for a small company - content-management-systemКак перенести окно WPF с помощью MVVM? - wpfAll Articles