MsSQL: Problem with query and variable

Status
Not open for further replies.

BEHD

Customer
Joined
Oct 14, 2019
Messages
11
Reaction score
1
Hello everyone,

I would like to modify the default query but if I use multiple time the variable in the WHERE clause, query does not work anymore.

EXAMPLE:

- This query work:
S_ELECT contactid, firstname, lastname, email, phonebusiness, phonemobile, faxbusiness F_ROM MyDBname.dbo.CRM3CX W_HERE phonebusiness L_IKE C_ONCAT('%',@ Number,'%')

- This query does not work:
S_ELECT contactid, firstname, lastname, email, phonebusiness, phonemobile, faxbusiness F_ROM MyDBname.dbo.CRM3CX W_HERE phonebusiness L_IKE C_ONCAT('%',S_UBSTRING(@ Number, P_ATINDEX('%[^0]%', @ Number+'.'), L_EN(@ Number)),'%')

Error message when I click test:
Must declare the scalar variable "@".

If I test in MS SQL Management Studio like this, query is working:
d_eclare @ Number v_archar( 64) s_et @ Number = '00123456789' S_ELECT contactid, firstname, lastname, email, phonebusiness, phonemobile, faxbusiness F_ROM MyDBname.dbo.CRM3CX W_HERE phonebusiness L_IKE C_ONCAT('%',S_UBSTRING(@ Number, P_ATINDEX('%[^0]%', @ Number+'.'), L_EN(@ Number)),'%')
Does anyone know what would be the problem and how to solve it ?

Thanks !

BEHD

Note. Of course, remove all "_" from queries.
[EDIT] Note2. To avoid forum translation, there's now a space between @ and Number, it should be removed to run query
 
Last edited:
Make sure all the @number have the capital N.
 
They all have a capital "N", it was changed after posting because forum translated them to a user called "number"...

But I take the opportunity to add the error message when I click on test with the second query:

Must declare the scalar variable "@".
 
Status
Not open for further replies.