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
 General SQL Server Forums
 New to SQL Server Programming
 Multiple statements in a single select statements

Author  Topic 

saurabh122
Starting Member

16 Posts

Posted - 2009-01-19 : 04:34:31
Hello all,

I want to form a select statement eith a bit of logic in it...but am not able to do so. the same is as follows:

select
begin
declare @value int
set @value = teststring
If PatIndex('%2%', @value) > 0
begin
while PatIndex('%2%', @value) > 0
begin
set @value = replace(@value, substring(@value,PATINDEX('%2%',@value), 7 ), 'qqq')
end
select @value
end
else
begin
select @value
end
end
from dateconversion

thanks

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-19 : 04:42:07
quote:
Originally posted by saurabh122

Hello all,

I want to form a select statement eith a bit of logic in it...but am not able to do so. the same is as follows:

select
begin
declare @value int
set @value = teststring
If PatIndex('%2%', @value) > 0

begin
while PatIndex('%2%', @value) > 0
begin
set @value = replace(@value, substring(@value,PATINDEX('%2%',@value), 7 ), 'qqq')
end
select @value
end
else
begin
select @value
end
end
from dateconversion

thanks




PATINDEX ( '%pattern%' , expression )

expression should be of the character string data type category.

int datatype is invalid

Jai Krishna
Go to Top of Page

saurabh122
Starting Member

16 Posts

Posted - 2009-01-19 : 04:45:07
thanks...
however, i do get the errors...
1. incorrect syntax near begin
2. incorrect syntax near end....

this occurs for the outermost begin and end

kindly help
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-19 : 04:53:35
try this
declare @value varchar(32)
set @value = '2test2string'
select case when PatIndex('%2%', @value) > 0
then replace(@value, substring(@value,PATINDEX('%2%',@value), 7 ), 'qqq')
else @value end
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-19 : 09:01:07
[code]
declare @value int
set @value = teststring
select
@value =case when PatIndex('%2%', @value) > 0
then stuff(@value, PATINDEX('%2%',@value), 7 , 'qqq')
else @value
end
from dateconversion
[/code]
Go to Top of Page
   

- Advertisement -