Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select from part of column

Author  Topic 

peanutong
Starting Member

3 Posts

Posted - 2008-08-24 : 23:04:19
how do i select data from a table by sorting the first word from a column?

for example:

"user1 hello"
"user2 one two three"
"user3 where are you"
"user1 im fine"

how can i select all the data starting with "user1"?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-24 : 23:09:55
[code]
select *
from yourtable
where data like 'user1%'
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peanutong
Starting Member

3 Posts

Posted - 2008-08-24 : 23:14:45
thank you for your prompt reply. however for user1, i'll be retrieving it from a control (lblShowUser.Text).

can i make it

select * from mytable where msg like '" & lblShowUser.Text & "'% ? will it work?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-24 : 23:16:21
yes



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-25 : 02:56:19
Better use stored procedure with input parameters

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -