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)
 Counting parameters

Author  Topic 

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-10-06 : 08:42:39
Hi,

Trying to write a stored proc with an If statement.

Trying to do the following:

If count(@param) > 1
THEN
'Select....'
ELSE
'Select.....'

But getting just simple error, syntax wrong near Then AND Else

Just trying to count the number of entries in the parameter, as its a multi value select parameter.

Any ideas? thanks

Kabila
Starting Member

33 Posts

Posted - 2009-10-06 : 08:47:00
If len(@param) > 1
THEN
'Select....'
ELSE
'Select.....'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-06 : 08:47:58
If len(@param)-LEN(replace(@param,',',''))+1 > 1
'Select....'
ELSE
'Select.....'


Madhivanan

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

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-10-06 : 08:59:05
Would it work same way

If (select len(Region) from table where (country in (@country)) > 1

quote:
Originally posted by madhivanan

If len(@param)-LEN(replace(@param,',',''))+1 > 1
'Select....'
ELSE
'Select.....'


Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-06 : 09:41:16
quote:
Originally posted by cipriani1984

Would it work same way

If (select len(Region) from table where (country in (@country)) > 1

quote:
Originally posted by madhivanan

If len(@param)-LEN(replace(@param,',',''))+1 > 1
'Select....'
ELSE
'Select.....'


Madhivanan

Failing to plan is Planning to fail




No

Madhivanan

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

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-10-06 : 09:45:00
it worked as:

If (select count(Region) from table where (country in (@country)) > 1

quote:
Originally posted by madhivanan

quote:
Originally posted by cipriani1984

Would it work same way

If (select len(Region) from table where (country in (@country)) > 1

quote:
Originally posted by madhivanan

If len(@param)-LEN(replace(@param,',',''))+1 > 1
'Select....'
ELSE
'Select.....'


Madhivanan

Failing to plan is Planning to fail




No

Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-07 : 02:14:45
Does @country have comma seperated values?

Madhivanan

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

- Advertisement -