-1

Is this correct?

Select [A], [B], [C] From [Database] Where [A] Like @TextBox1%
Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
Masoud
  • 1
  • 1

1 Answers1

0

The correct is:

Select field1, field2, ... From table Where fieldx like '%whatever%';
  • %whatever%' => anywhere in the field
  • 'whatever%' => at the start the field
  • '%whatever' => at the end of the field
Nelson Teixeira
  • 6,297
  • 5
  • 36
  • 73
  • 1
    Your `whatever%` and `%whatever` explanations are backwards. `whatever%` is looking for a string that starts with `whatever`, and `%whatever` is looking for a string that ends with `whatever`. – Siyual May 05 '16 at 20:59
  • I am trying to pull data from a Canadian database that I have. If customer enters A0K in my text box, there are many A0K in the column such as A0K 1A0, A0K 1B0 etc... – Masoud May 05 '16 at 21:08
  • SELECT [Province], [Zone], [Degree], [UValueMetric], [UValueEnglish], [EnergyRating] FROM [PostalCode] WHERE ([PostalCode] LIKE '%@PostalCode%') – Masoud May 05 '16 at 21:09
  • where are you putting this sql ? and why have you added a @ and a ( ) ? – Nelson Teixeira May 05 '16 at 21:10
  • This is asp page and the @PostalCode is the textbox name. – Masoud May 05 '16 at 21:12
  • I don't know asp.net, but judging from this answer here http://stackoverflow.com/questions/15893098/asp-net-sqldatasource-like-on-selectcommand, it seems correct. It should be just some quotes issue. I can't help anymore. Sorry. – Nelson Teixeira May 05 '16 at 21:26
  • When you run debugging, what is the exception message? It seems basic matter of usage. The key must be in the exception message. My instant little tip is to avoid same name when making a parameter. – Kay Lee May 06 '16 at 00:06
  • Figured it out, in asp.net you will pass on the % using the control name then + %. Thank you all for your help. – Masoud May 06 '16 at 13:26