Active Server Pages Programming (ASP)/Problem in Programming

Advertisement


Question
Hello sir,
Thanks for response.Your solution works well.but the id datatype is varchar.so when @Value  returns '1' with single quotes why it doesn,t run.
because during hardcode it runs well
select * from ncdex where id= '1'
Regards
Ankit
-------------------------
Followup To
Question -
Sir Read the following code .I have a problem at line no. 11 where i run my actual query .In line no 10 i got succesfully the value in a variable @Value.But it wont work in query .And  output of query remains nothing.but when  i hardcode in place of @value in my query at line 11 then it works well.What is the problem i dont know.Sir please help me and reply soon

The Code starts now:


1 DECLARE @Array varchar(8000)
2 DECLARE @Comma char, @Value char(8000)
3 SET @Array ='''1'',''2'',''3'',''4'''
4 WHILE @Array <> ''
5 BEGIN
6  SET @Comma = CharIndex(',', @Array)
7    IF @Comma > 0
8        BEGIN
9  select @Array
10  SET @Value = Cast(Left(@Array,@Comma-1) AS  char)

11  select symbol_name from ncdex where id = @Value
12  select @Value
13  SET @Array = Right(@Array, Len(@Array) - @Comma)
14        END
   ELSE
       BEGIN

         SET @Value = Cast(@Array AS char)

         SET @Array=''
       END
END


Regards
Ankit jain
Answer -
Hi

Try your 3rd line like this

SET @Array ='1,2,3,4'

the problem is  @Value  returns '1' with single quotes

in this line

select symbol_name from ncdex where id = @Value

ncdex is a integer data type

Happy programming!!

-srini

Answer
Hi

When you declare @Value as a varchar, the system thinks you are comparing string vs. string so and automatically it adds single quotes...

so this will work as is:

declare @Value varchar(10)
set @Value = '1'
select symbol_name from ncdex where id = @Value



Happy Programming!

-Srini

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.

©2012 About.com, a part of The New York Times Company. All rights reserved.