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.
| Author |
Topic |
|
argon007
Starting Member
38 Posts |
Posted - 2008-06-12 : 14:27:53
|
quote: list the first and the last name of the employee with a name of Thomas. Use local variables for the first name and the last name and the @@ROWCOUNT command.
SET NOCOUNT ONDECLARE @variable varchar(50)SET @variable = 'name'SELECT @variable = fname + ' ' + lnameFROM employeeWHERE @variable = '%Thomas%'IF @@ROWCOUNT > 0PRINT 'Employee Name is ' + @variableELSEPRINT 'Employee not found' when i execute it, it said employee not found. what do i need to add or revise?it should be: quote: Employee Name is Argon Thomas.
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-12 : 14:30:43
|
| If you want to use % for searching use LIKE. ANd if you use = for comparison dont use %SET NOCOUNT ONDECLARE @variable varchar(50)SET @variable = 'name'SELECT @variable = fname + ' ' + lnameFROM employeeWHERE @variable LIKE '%Thomas%'IF @@ROWCOUNT > 0PRINT 'Employee Name is ' + @variableELSEPRINT 'Employee not found' |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-06-12 : 14:32:57
|
| [code]SET NOCOUNT ONDECLARE @Fname varchar(50), @Lname varchar(50)SET @FName = 'Thomas'SELECT fname + ' ' + lnameFROM employeeWHERE FName Like '%' + @Fname + '%'IF @@ROWCOUNT > 0PRINT 'Employee Name is ' + @variableELSEPRINT 'Employee not found'[/code]Chiraghttp://www.chirikworld.com |
 |
|
|
argon007
Starting Member
38 Posts |
Posted - 2008-06-12 : 17:13:00
|
| try it above, but it is the same problem. i don't know what it is wrong.and Argon Thomas is on the employee table. i don't know why. |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-06-12 : 17:31:56
|
| [code]SET NOCOUNT ONDECLARE @variable varchar(50)SELECT @variable = fname + ' ' + lnameFROM @employeeWHERE fname + ' ' + lname LIKE '%thomas%'IF @@ROWCOUNT > 0PRINT 'Employee Name is ' + @variableELSEPRINT 'Employee not found'[/code]Chiraghttp://www.chirikworld.com |
 |
|
|
argon007
Starting Member
38 Posts |
Posted - 2008-06-13 : 03:15:53
|
| thanks, problem solved. |
 |
|
|
|
|
|