Home All Groups Group Topic Archive Search About

CHARINDEX is not working

Author
1 Dec 2005 11:33 PM
KL
i am using the below code but its not working .. what could be the reason?

CHARINDEX(@SPName,@DateAndIntCols)

to CHARINDEX function i am passing to variables, cant i pass variables to
CHARINDEX?

Author
1 Dec 2005 11:45 PM
ML
Please elaborate on "not working" . Are there errors? Don't you get expected
results? Don't you get any results? What?


ML

---
http://milambda.blogspot.com/
Author
2 Dec 2005 12:03 AM
KL
I am passing the below values to the variables but its still returning 0...
SET @SPName ='eUpdated'
SET @DateAndIntCols = 'eUpdated,eDeleted'
but its working (returning 1) when use the following one...
SET @DateAndIntCols = 'eUpdated,eDeleted'
CHARINDEX('eUpdated',@DateAndIntCols)



Show quote
"ML" wrote:

> Please elaborate on "not working" . Are there errors? Don't you get expected
> results? Don't you get any results? What?
>
>
> ML
>
> ---
> http://milambda.blogspot.com/
Author
2 Dec 2005 12:14 AM
Hugo Kornelis
On Thu, 1 Dec 2005 16:03:03 -0800, KL wrote:

>I am passing the below values to the variables but its still returning 0...
>SET @SPName ='eUpdated'
>SET @DateAndIntCols = 'eUpdated,eDeleted'
>but its working (returning 1) when use the following one...
>SET @DateAndIntCols = 'eUpdated,eDeleted'
>CHARINDEX('eUpdated',@DateAndIntCols)

Hi KL,

Works for me:

DECLARE @SPName varchar(10), @DateAndIntCols varchar(100)
SET @SPName ='eUpdated'
SET @DateAndIntCols = 'eUpdated,eDeleted'

SELECT CHARINDEX(@SPName,@DateAndIntCols)


Can you please post your complete code?

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Author
2 Dec 2005 12:24 AM
vsr
Here is the code i am using .....

DECLARE
@SPName varchar(128) ,
@DateAndIntCols varchar(1000)
SELECT @SPName='eUpdated'
SELECT @DateAndIntCols=DateAndIntCols FROM MetaData WHERE SPID='CC-3'
SELECT CHARINDEX(@SPName,@DateAndIntCols)
And when i printed the variable @DateAndIntCols its showing as
'eUpdated,eDeleted'.....

Show quote
"Hugo Kornelis" wrote:

> On Thu, 1 Dec 2005 16:03:03 -0800, KL wrote:
>
> >I am passing the below values to the variables but its still returning 0...
> >SET @SPName ='eUpdated'
> >SET @DateAndIntCols = 'eUpdated,eDeleted'
> >but its working (returning 1) when use the following one...
> >SET @DateAndIntCols = 'eUpdated,eDeleted'
> >CHARINDEX('eUpdated',@DateAndIntCols)
>
> Hi KL,
>
> Works for me:
>
> DECLARE @SPName varchar(10), @DateAndIntCols varchar(100)
> SET @SPName ='eUpdated'
> SET @DateAndIntCols = 'eUpdated,eDeleted'
>
> SELECT CHARINDEX(@SPName,@DateAndIntCols)
>
>
> Can you please post your complete code?
>
> Best, Hugo
> --
>
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>
Author
2 Dec 2005 12:26 AM
KL
Here is the complete code i am using .....
DECLARE
@SPName varchar(128) ,
@DateAndIntCols varchar(1000)
SELECT @SPName='eUpdated'
SELECT @DateAndIntCols=DateAndIntCols FROM MetaData WHERE SPID='CC-3'
SELECT CHARINDEX(@SPName,@DateAndIntCols)
And when i printed the variable @DateAndIntCols its showing as
'eUpdated,eDeleted'.....


Show quote
"Hugo Kornelis" wrote:

> On Thu, 1 Dec 2005 16:03:03 -0800, KL wrote:
>
> >I am passing the below values to the variables but its still returning 0...
> >SET @SPName ='eUpdated'
> >SET @DateAndIntCols = 'eUpdated,eDeleted'
> >but its working (returning 1) when use the following one...
> >SET @DateAndIntCols = 'eUpdated,eDeleted'
> >CHARINDEX('eUpdated',@DateAndIntCols)
>
> Hi KL,
>
> Works for me:
>
> DECLARE @SPName varchar(10), @DateAndIntCols varchar(100)
> SET @SPName ='eUpdated'
> SET @DateAndIntCols = 'eUpdated,eDeleted'
>
> SELECT CHARINDEX(@SPName,@DateAndIntCols)
>
>
> Can you please post your complete code?
>
> Best, Hugo
> --
>
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>
Author
2 Dec 2005 11:55 PM
Hugo Kornelis
On Thu, 1 Dec 2005 16:26:02 -0800, KL wrote:

>Here is the complete code i am using .....
>DECLARE
>@SPName varchar(128) ,
>@DateAndIntCols varchar(1000)
>SELECT @SPName='eUpdated'
>SELECT @DateAndIntCols=DateAndIntCols FROM MetaData WHERE SPID='CC-3'
>SELECT CHARINDEX(@SPName,@DateAndIntCols)
>And when i printed the variable @DateAndIntCols its showing as
>'eUpdated,eDeleted'.....

Hi KL,

Since I don;t have your table, I had to add some lines to the script.
Here's what I executed:

CREATE TABLE MetaData
    (SPID char(4) NOT NULL PRIMARY KEY,
     DateAndIntCols varchar(1000) NOT NULL)
INSERT INTO MetaData (SPID, DateAndIntCols)
VALUES ('CC-3', 'eUpdated,eDeleted')
go
DECLARE
@SPName varchar(128) ,
@DateAndIntCols varchar(1000)
SELECT @SPName='eUpdated'
SELECT @DateAndIntCols=DateAndIntCols FROM MetaData WHERE SPID='CC-3'
SELECT CHARINDEX(@SPName,@DateAndIntCols)
go
DROP TABLE MetaData
go

And here's the output:


-----------
1

This is the expected output. What output are you getting? Also, what is
the output if you execute
  SELECT @@VERSION

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Author
2 Dec 2005 12:00 AM
Hugo Kornelis
On Thu, 1 Dec 2005 15:33:02 -0800, KL wrote:

>i am using the below code but its not working .. what could be the reason?
>
>CHARINDEX(@SPName,@DateAndIntCols)
>
>to CHARINDEX function i am passing to variables, cant i pass variables to
>CHARINDEX?

Hi KL,

The following code returns 4 on my computer, which is as expected. What
are the values of @SPName and @DateAndIntCols in your case, and what was
the result you got?


DECLARE @SPName varchar(10), @DateAndIntCols varchar(100)
SET @SPName = 'xyz'
SET @DateAndIntCols = 'uvwxyzabcdef'

SELECT CHARINDEX(@SPName,@DateAndIntCols)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

AddThis Social Bookmark Button