By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

how Create sql like Query with dynamic

P: 13
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[SelectResultAllDatails]
  2.  
  3. AS
  4. BEGIN
  5.  
  6. DECLARE @query nvarchar(max), @VALUE NVARCHAR(10)
  7.  
  8. SET @VALUE = 'D013'
  9.  
  10. SET @QUERY = 'select * from dbo.ResultsDetails where [Student Index] LIKE ''' + @VALUE + '%''' 
  11.  
  12. SELECT @query
  13.  
  14. END
  15. GO
Jun 28 '14 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,430
Please use code tags when posting code or formatted data.

Use an input parameter. You can read more about creating procedures from microsoft's documentation: http://msdn.microsoft.com/en-us/library/ms187926.aspx. You also shouldn't build a SQL string that way, it's subject to SQL injection attacks.
Jun 29 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.