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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:22:10+00:00 2026-05-15T19:22:10+00:00

In my application i am implementing search, it is like when user enter text

  • 0

In my application i am implementing search, it is like when user enter text separated with comma in a text box, search result will be displayed. This is my requirement and for this i write a procedure for this it is like this…….

create procedure [dbo].[videos_getSearch](@searchstring AS VARCHAR(1000)) 
AS 
BEGIN  

DECLARE @CurNumber INT, @CommaIndex INT, @strSearch varchar(3000),@str varchar(50) 
declare @strQuery varchar(1000),@result varchar(5000) 
declare @sql varchar(2000) 
DECLARE @CurNumStr VARCHAR(20) 

  set @strSearch = '' 

 WHILE LEN(@searchstring) > 0 
 BEGIN 

     SET @CommaIndex = CHARINDEX(',', @searchstring) 
     IF @CommaIndex = 0 SET @CommaIndex = LEN(@searchstring)+1 
     SET @CurNumStr = SUBSTRING(@searchstring, 1, @CommaIndex-1) 
     SET @searchstring = SUBSTRING(@searchstring, @CommaIndex+1, LEN(@searchstring)) 

    BEGIN 

        set @str = ltrim(rtrim(@CurNumStr)) 
        if LEN(@searchstring)> 0 
          begin 
            set @strSearch = @strSearch + '''%' + @str +'%'''+'or tags like'  
          end 
        else 
          begin 
            set @strSearch = @strSearch + '''%'+ @str +'%''' 
          end 
    END 
 END 



    set @sql='SELECT  phot_album.albumid,phot_album.tags,phot_album.albumtitle,phot_album.coverphoto,trailor_creation.trailorid,trailor_creation.tags,trailor_creation.movie,trailor_creation.images,video_upload.videoid,video_upload.videotitle,video_upload.videofile,video_upload.tags FROM   phot_album   INNER JOIN   trailor_creation ON phot_album.tags = trailor_creation.tags INNER JOIN   video_upload  ON phot_album.tags = video_upload.tags where (phot_album.tags)  like  '+@strSearch  +' or  (trailor_creation.tags)  like '+@strSearch  +' or  (video_upload.tags) like '+@strSearch  
     execute (@sql)

 END

when i run this procedure it is giving error like ambigious ‘tags’ in this procedure i am joining 3 tables . can u help me

Ambiguous column name ‘tags’.
Msg 209, Level 16, State 1, Line 1
Ambiguous column name ‘tags’.
Msg 209, Level 16, State 1, Line 1
Ambiguous column name ‘tags’.

  • 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-15T19:22:11+00:00Added an answer on May 15, 2026 at 7:22 pm

    Your current approach using dynamic SQL based on user input is vulnerable to SQL injection. I have altered it so the search terms get put into a table variable that is then joined on. This is safer.

    Additionally I’m not sure about the desired semantics. Your dynamic SQL WHERE clause is where (phot_album.tags) like '+@strSearch +' or (trailor_creation.tags) like '+@strSearch +' or (video_upload.tags) like '+@strSearch

    but your JOIN clause brings back records joined on tag. In which case the tag value in all of the tables will be the same and it is only necessary to check one of them.

    CREATE PROCEDURE [dbo].[videos_getSearch](@searchstring AS VARCHAR(1000)) 
    AS 
    BEGIN  
    
    DECLARE @CurNumber INT, @CommaIndex INT, @strSearch VARCHAR(3000),@STR VARCHAR(50) 
    DECLARE @strQuery VARCHAR(1000),@RESULT VARCHAR(5000) 
    DECLARE @SQL VARCHAR(2000) 
    DECLARE @CurNumStr VARCHAR(20) 
    
    
     WHILE LEN(@searchstring) > 0 
     BEGIN 
    
         SET @CommaIndex = CHARINDEX(',', @searchstring) 
         IF @CommaIndex = 0 SET @CommaIndex = LEN(@searchstring)+1 
         SET @CurNumStr = SUBSTRING(@searchstring, 1, @CommaIndex-1) 
         SET @searchstring = SUBSTRING(@searchstring, @CommaIndex+1, LEN(@searchstring)) 
    
         DECLARE @SearchTerms TABLE
         (
         Term VARCHAR(50)
         )
    
        BEGIN 
    
            SET @STR = LTRIM(RTRIM(@CurNumStr)) 
           INSERT INTO @SearchTerms VALUES (@STR)
        END 
     END 
    
    
    SELECT phot_album.albumid        ,
           phot_album.tags           ,
           phot_album.albumtitle     ,
           phot_album.coverphoto     ,
           trailor_creation.trailorid,
           trailor_creation.tags     ,
           trailor_creation.movie    ,
           trailor_creation.images   ,
           video_upload.videoid      ,
           video_upload.videotitle   ,
           video_upload.videofile    ,
           video_upload.tags
    FROM   phot_album
           INNER JOIN trailor_creation
           ON     phot_album.tags = trailor_creation.tags
           INNER JOIN video_upload
           ON     phot_album.tags = video_upload.tags
           INNER JOIN @SearchTerms ST
           ON     phot_album.tags LIKE '%' + ST.Term + '%'
    
    
    
     END
    

    Actually I’m going to guess that something like this might be more what you need. Does the tags column in the tables contain a comma delimited list of tags? If so putting this into first normal form will allow this query to be simpler and more efficient.

    CREATE PROCEDURE [dbo].[videos_getSearch]
    (
    @searchstring AS VARCHAR(1000)
    )
    AS
        BEGIN
    
            DECLARE @SearchTerms TABLE 
            ( 
            Term VARCHAR(50) 
            )
    
            DECLARE @CommaIndex INT
            DECLARE @CurNumStr  VARCHAR(20)
    
            WHILE LEN(@searchstring) > 0
            BEGIN
                SET @CommaIndex   = CHARINDEX(',', @searchstring)
    
                IF @CommaIndex    = 0
                    SET @CommaIndex   = LEN(@searchstring)+1
    
                SET @CurNumStr    = SUBSTRING(@searchstring, 1, @CommaIndex-1)
                SET @searchstring = SUBSTRING(@searchstring, @CommaIndex+1, LEN(@searchstring))
    
                BEGIN
                    INSERT
                    INTO @SearchTerms VALUES
                        ('%' + LTRIM(RTRIM(@CurNumStr)) + '%')
                END
            END
    
    
            SELECT 'phot_album'    AS Source   ,
                phot_album.albumid AS entityId ,
                phot_album.tags                ,
                phot_album.albumtitle AS title ,
                phot_album.coverphoto AS image
            FROM phot_album
                INNER JOIN @SearchTerms ST
                ON  phot_album.tags LIKE ST.Term
    
            UNION ALL
    
            SELECT 'trailor_creation' AS Source ,
                trailor_creation.trailorid      ,
                trailor_creation.tags           ,
                trailor_creation.movie          ,
                trailor_creation.images
            FROM trailor_creation
                INNER JOIN @SearchTerms ST
                ON  trailor_creation.tags LIKE ST.Term
    
            UNION ALL
    
            SELECT 'video_upload' AS Source ,
                video_upload.videoid        ,
                video_upload.tags           ,
                video_upload.videotitle     ,
                video_upload.videofile
            FROM video_upload
                INNER JOIN @SearchTerms ST
                ON  video_upload.tags LIKE ST.Term
        END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing the application just like tracking the user's traveling. Now I'm using the
I am implementing a search application. Corpus is large text documents. During file process
I have an application implementing incremental search. I have a catalog of unicode strings
We're implementing solr with ecommerce application. The main objective is faster search and better
I am implementing an eCommerce application using ASP.Net. I would like to know if
I am implementing mobile local search in iPhone application: - (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText
I'm using lazy loading images based on this question . I'm implementing a search
Can any one get me idea in implementing the spotlight search inside application for
The document says : packageContext A Context of the application package implementing this class.
I'm working on an application that will be implementing a hex value as a

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.