Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6075653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:31:06+00:00 2026-05-23T10:31:06+00:00

Right now, I am trying to get rid of some old searching code in

  • 0

Right now, I am trying to get rid of some old searching code in a delphi programm, and I want to push the searching to the sql-server the program is using. For this I created this query, which is very similar to a query I use in a different C# program.

The query works just fine using the SQL Management Studio or from a C# program, but with Delphi I get a “Cursor not returned from query” error.

This is the query

DECLARE @SearchString NVARCHAR(MAX);
SET @SearchString = ':Param1';
IF @SearchString = '' SET @SearchString = '%';

--Table for splitted values
DECLARE @SearchItms TABLE
(
Item NVARCHAR(MAX)
)

--Split Operator
DECLARE @SplitOn NVARCHAR(MAX)
SET @SplitOn = ' '; --Split Keywords on space

--Splitting
While (Charindex(@SplitOn,@SearchString)>0)
Begin
    Insert Into @SearchItms (Item)
    Select ('%' + Substring(@SearchString,1,Charindex(@SplitOn,@SearchString)-1) + '%')

    Set @SearchString = Substring(@SearchString,Charindex(@SplitOn,@SearchString)+1,len(@SearchString))
End

--Add last Item
Insert Into @SearchItms (Item) 
Select ('%' + @SearchString + '%')

--Select fitting items
SELECT MyTable.*
FROM MyTable INNER JOIN SecondTable ON (MyTable.Key = SecondTable.Key)
WHERE
NOT EXISTS(
  SELECT * FROM @SearchItms WHERE NOT(
     (OneField IS NOT NULL AND OneField LIKE Item)
  OR (OneDateField IS NOT NULL AND (convert(varchar, OneDateField, 104) LIKE Item) OR (convert(varchar, OneDateField, 114) LIKE Item ) )
  OR (AnotherField IS NOT NULL AND AnotherField LIKE Item)
  OR (LastField IS NOT NULL AND LastField LIKE Item)
  )
)

One strange thing is, that when I remove

--Add last Item
Insert Into @SearchItms (Item) 
Select ('%' + @SearchString + '%')

I don’t get the “Cursor not returned from query” error. But with a search string, where I get only 10 Results in the SQL Management Studio, I get all items in the database in Delphi, like the search did not do anything.

This happens also in a simple test program where I just have a Form, a TSQLConnection, TSQLQuery, TDataSetProvider and a ClientDataSet.

Can someone tell me whats the problem here? Since the query works fine in other environments, I think it should be OK.

Many thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:31:07+00:00Added an answer on May 23, 2026 at 10:31 am

    As ldsandon mentioned in his post, the problem seems to be, that its not a simple Query, but a complete script. But since non of the other dbExpress units seems to be able to handle this I found a way to make it working.

    Just add a SET NOCOUNT ON; to the beginning of the script, and close the script with SET NOCOUNT OFF;

    I think this surpresses the ‘xx rows effected’ message from the inserts and therefore makes it possible to run without errors.

    If you know a better way to run the script without errors, let me know.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get rid of old unsafe C functions, including sscanf(). Right now
I'm trying to get rid of some hints(*) the Delphi compiler emits. Browsing through
I'm trying to get data from a server. Right now, I am polling the
Right now I'm trying desperately to get @font-face to work in my website. This
I'm at my wits end right now trying to get a website working in
Right now I am trying to create a producer/consumer thread, the producer thread goes
Right now I am trying to solve Project Euler 71 . Consider the fraction,
Right now I'm trying to create my own tiny MVC (just for practice and
Right now I'm trying this: int a = round(n); where n is a double
Right now I'm trying to set the default audio device on Windows 7 programmatically,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.