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 6760013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:01:06+00:00 2026-05-26T14:01:06+00:00

I’ve inherited a db etc from another developer and need some help. I have

  • 0

I’ve inherited a db etc from another developer and need some help.

I have the following stored procedure:

CREATE PROCEDURE [dbo].[TESTgetSearchResults] 
    (
    @ids varchar(100),
    @Date DateTime = Null, 
    @Date2 DATETIME = Null,
    @Sort VARCHAR(5), /* ASC or DESC */
    @SortBy VARCHAR(10), /* Sorting criteria */
    @Location VARCHAR(40)
    )
AS
    SELECT @Date = GetDate()
    SELECT @Date2 = DATEADD(day,-14,GETDATE())    

BEGIN
    SELECT Aircraft.Id AS AircraftID, AircraftManufacturers.Name, AircraftModels.ModelName, 
    Aircraft.ModelSuffix, Aircraft.ImageFileName, Aircraft.Year, Aircraft.SerialNo, 
    Locations.DescriptionForSite, Aircraft.Description, Aircraft.Description2, 
    Aircraft.InfoWebAddress, Aircraft.ImageDescription, Advertisers.Id AS AdvertisersID, 
    Advertisers.Name AS AdvertisersName, Aircraft.AircraftDataId, Aircraft.ForSale, Aircraft.ForLease, 
    Aircraft.TTAF, Aircraft.ReSend, Aircraft.ReSendReason, Aircraft.Registration, Aircraft.AdType,
    Aircraft.HasAlternateImage, Aircraft.AlternateImageDescription, 
    Aircraft.Price, AircraftModels.AircraftType, Advertisers.CurrentEMagLink, Aircraft.CurrentEMagLink, 
    Aircraft.Email, Aircraft.IsSold, Aircraft.SoldDate, Aircraft.DateAdded, Aircraft.ExtendedDetails, 
    Aircraft.LastUpdateDate, Aircraft.ImageCount, Aircraft.ContactTelephone, AircraftModels.id, Advertisers.IsPremiumAdvertiser,
    Aircraft.Location, Advertisers.ContactTelephone As AdvertisersTelephone, Aircraft.EndDate, Aircraft.VideoLink,
    Aircraft.Contact, Advertisers.WASSalesEmail, Advertisers.WASSalesEmail2, Aircraft.PriceNumeric, 
    Aircraft.PriceQualifier, Aircraft.Currency, Aircraft.AircraftDescription
    FROM (((Aircraft 
    INNER JOIN Advertisers ON Aircraft.AdvertiserId = Advertisers.Id) 
    INNER JOIN AircraftModels ON Aircraft.AircraftModelId = AircraftModels.Id) 
    INNER JOIN AircraftManufacturers ON AircraftModels.ManufacturerId = AircraftManufacturers.Id) 
    INNER JOIN Locations ON Aircraft.LocationId = Locations.Id
    JOIN iter$simple_intlist_to_tbles(@ids) i ON AircraftModels.id = i.number
    WHERE (Aircraft.IsActive=1 AND Advertisers.IsActive=1 AND Aircraft.IsSold=0 AND (Aircraft.EndDate>=@Date OR Aircraft.EndDate Is Null) AND Locations.Id = @Location)
    OR (Aircraft.IsActive=1 AND Advertisers.IsActive=1 AND Aircraft.IsSold=1 AND Aircraft.SoldDate>=@Date2 AND Locations.Id = @Location)
    ORDER BY Advertisers.IsPremiumAdvertiser ASC, Aircraft.DateAdded DESC, Aircraft.ListPosition DESC, 
    Aircraft.LastUpdateDate, AircraftManufacturers.Name, AircraftModels.ModelName, Aircraft.ModelSuffix, 
    Aircraft.Id DESC
END

iter$simple_intlist_to_tbles(@ids) simple builds a table from the @ids input. This input comes in the form of a strings of id numbers seperated by a ‘,’ eg ,1,,2,,3,,4, etc…

Now I need to replace the @Location with a string of location IDs formatted in this same fashion eg ,1,,2,,3,,4, etc….

So my problem is this… How do I adapt the above sql/ stored procedure so that the two ‘WHERE’ clauses which filter based on a single location, are now able to take multiple location IDs ??????

Any help would be really appreciated.

Thanks.

  • 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-26T14:01:07+00:00Added an answer on May 26, 2026 at 2:01 pm

    To solve your problem, simply retrieve the values from iter$simple_intlist_to_tbles(@Location) in a subquery, and check for them with IN:

    AND Locations.Id IN (SELECT * FROM iter$simple_intlist_to_tbles(@Location))
    

    Your where clause is also more complex that it needs to be. There are identical AND requirements in each OR, so you can move them outside the OR. It simplifies to:

    WHERE Aircraft.IsActive=1 
    AND Advertisers.IsActive=1 
    AND ((Aircraft.IsSold=0 AND (Aircraft.EndDate>=@Date OR Aircraft.EndDate Is Null))
      OR (Aircraft.IsSold=1 AND Aircraft.SoldDate>=@Date2))
    AND Locations.Id IN (SELECT * FROM iter$simple_intlist_to_tbles(@Location))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.