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 |
|
jerrypaz
Starting Member
18 Posts |
Posted - 2004-10-28 : 21:27:47
|
| I created a Stored Procedure with a SELECT statement I know works. Here's the SP:CREATE PROCEDURE [dbo].[QueryDesc]( @desc ntext) ASif exists(SELECT gr [Group], org Organization, sq Squadron, officeDesc Office, officeNum Extension FROM dbo.tblOrg, dbo.tblOffice, dbo.tblGroup, dbo.tblSqWHERE dbo.tblOrg.orgID = dbo.tblOffice.orgID AND dbo.tblSq.sqID = dbo.tblOffice.sqID AND dbo.tblSq.grID = dbo.tblGroup.grID AND dbo.tblOffice.officeDesc LIKE '%' + '@desc' + '%')beginSELECT gr [Group], org Organization, sq Squadron, officeDesc Office, officeNum Extension FROM dbo.tblOrg, dbo.tblOffice, dbo.tblGroup, dbo.tblSqWHERE dbo.tblOrg.orgID = dbo.tblOffice.orgID ANDdbo.tblSq.sqID = dbo.tblOffice.sqID ANDdbo.tblSq.grID = dbo.tblGroup.grID ANDdbo.tblOffice.officeDesc LIKE '%' + '@desc' + '%'ENDif exists(SELECT gr [Group], sq Squadron, officeDesc Office, officeNum Extension FROM dbo.tblOffice, dbo.tblGroup, dbo.tblSqWHEREdbo.tblSq.grID = dbo.tblGroup.grID ANDdbo.tblSq.sqID = dbo.tblOffice.sqID ANDdbo.tblOffice.officeDesc LIKE '%' + '@desc' + '%')begin SELECT gr [Group], sq Squadron, officeDesc Office, officeNum Extension FROM dbo.tblOffice, dbo.tblGroup, dbo.tblSqWHEREdbo.tblSq.grID = dbo.tblGroup.grID ANDdbo.tblSq.sqID = dbo.tblOffice.sqID ANDdbo.tblOffice.officeDesc LIKE '%' + '@desc' + '%'ENDelsebeginSELECT gr [Group], officeDesc Office, officeNum Extension FROM dbo.tblOffice, dbo.tblGroupWHEREdbo.tblOffice.grID = dbo.tblGroup.grID ANDdbo.tblOffice.officeDesc LIKE '%' + '@desc' + '%'ENDGOWhen I run the SELECT statement by itself with a constant value, the SELECT statement works just fine. Why won't it work in the SP??? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-10-28 : 21:41:44
|
| You have single quotes around @desc. Should be:LIKE '%' + @desc + '%'Do you really need that first % sign? That's a performance issue. And also, ntext data type?Tara |
 |
|
|
jerrypaz
Starting Member
18 Posts |
Posted - 2004-10-28 : 21:46:46
|
| That did the trick. I knew it had to be something simple like that.Thanks |
 |
|
|
|
|
|
|
|