T-SQL : Searching values in several table


This question already has an answer here:


You will certainly have to use some form of dynamic SQL to perform this search. An example (which you could pull into a function if you so desired):

declare @sqlstmt nvarchar(MAX)
declare @tablename nvarchar(100)
declare @username nvarchar(100)

set @tablename = 'UserProfile'
set @username = 'janed'
set @sqlstmt = 'select count(*) from ' + @tablename + ' where username = ''' + @username + ''''

exec sp_executesql @sqlstmt 

Need Your Help

Complete TextBox AutoComplete Example – Getting data from database

c# jquery sql asp.net json

I am trying to auto complete a text box with Names from a database. When I go to type in the text box when it is running nothing happens.

Connection error 1044 when connecting to a database with PHP

php mysql

I'm trying to connect to a MySQL database by using PHP. The PHP code that I have is: