Hi!
I want to execute the sql query based on the question. For Example, In Textbox If i enter the question like "What are the department in allahabaduniversity" means following query will be executed "select department from allahabaduniversity;" , Here department is a filed and allahabaduniversity is table,
Please Help Me to do this...
Thanks!
Regards!
G.Arun Prasath
Loading

Anuja PawarRank #1,404 · 1.2K reputationPosted Jan 24, 2012, 12:12 AM EST
If every time last value will be your table then you can split the string and take the last word and apply your select query on that. Something like this......
create function dbo.SplitString
(
@str nvarchar(4000),
@separator char(1)
)
returns table
AS
return (
with tokens(p, a, b) AS (
select
1,
1,
charindex(@separator, @str)
union all
select
p + 1,
b + 1,
charindex(@separator, @str, b + 1)
from tokens
where b > 0
)
select
p-1 zeroBasedOccurance,
substring(
@str,
a,
case when b > 0 then b-a ELSE 4000 end)
AS s
from tokens
)
GO
select s
from dbo.SplitString('What are the department in allahabaduniversity', ' ')
where zeroBasedOccurance=5
arun prasath94 reputationPosted Jan 24, 2012, 1:30 AM EST
Thanks!
Regards!
G.Arun Prasath
Anuja PawarRank #1,404 · 1.2K reputationPosted Jan 24, 2012, 3:27 AM EST
Create the function given. Create an SP in which you can pass your text box value as a parameter. And apply the query. Get the output and supply that to a variable or dataset.
arun prasath94 reputationPosted Jan 24, 2012, 9:48 PM EST
Suthish NairRank #92 · 22.8K reputationPosted Jan 24, 2012, 11:32 PM EST
Lots of samples avaliable..
Refer Links 1, 2
MSDN Links 1, 2
Anuja PawarRank #1,404 · 1.2K reputationPosted Jan 25, 2012, 3:31 AM EST
Assuming you have created the split function. This is how you can create procedure