0
dim Symbol_Val as string

I put my preference in entering the stocks according to my order in symbol_val

For example

Symbol val="stock1,stock2,stock3,stock4,stock5,stock6,stock7,stock8,stock9"

Then I execute the query

"Select Symbol, trade_date , sec_close,volume from stockPrice WHERE symbol in (" & Symbol_Val & ") and NO_OF_RECORDS= (SELECT max(no_of_records) FROM stockPrice_Alert) ORDER BY" & Symbol_Val

When I execute the query I am not getting the records as per my preference can anyone tell me what the query is required to be execute in SQL?

1 Answer 1

1

One method is to use charindex() to find the value. A simplistic method is:

Select Symbol, trade_date, sec_close, volume
from stockPrice
where symbol in (" & Symbol_Val & ") and NO_OF_RECORDS = (SELECT max(no_of_records) FROM stockPrice_Alert)
order by charindex(Symbol_Val, val)

It is better to take the delimiters into account:

order by charindex(','+Symbol_Val+',', ','+val+',')
Sign up to request clarification or add additional context in comments.

1 Comment

This charindex function is not recognized by sql 6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.