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 PawarPosted Jan 25, 2012, 8:31 AM
Assuming you have created the split function. This is how you can create procedure
Suthish NairPosted Jan 25, 2012, 4:32 AM
Lots of samples avaliable..
Refer Links 1, 2
MSDN Links 1, 2
arun prasathPosted Jan 25, 2012, 2:48 AM
Anuja PawarPosted Jan 24, 2012, 8:27 AM
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 prasathPosted Jan 24, 2012, 6:30 AM
Thanks!
Regards!
G.Arun Prasath
Anuja PawarPosted Jan 24, 2012, 5:12 AM
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