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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:51:24+00:00 2026-05-14T04:51:24+00:00

I need a function, but cannot seem to get it quite right, I have

  • 0

I need a function, but cannot seem to get it quite right, I have looked at examples here and elsewhere and cannot seem to get this just right, I need an optional item to be included in my query, I have this query (which works):

SELECT TOP 100 PERCENT SKU, Description, LEN(CONVERT(VARCHAR
(1000),Description)) AS LenDesc FROM tblItem
WHERE Title = @Title AND Manufacturer = @Manufacturer
ORDER BY LenDesc DESC

This works within a Function, however the Manufacturer is Optional for this search – which is to find the description of a similar item, if none is present, the other query is:

SELECT TOP 100 PERCENT SKU, Description, LEN(CONVERT(VARCHAR
(1000),Description)) AS LenDesc FROM tblItem
WHERE Title = @Title ORDER BY LenDesc DESC

Which is missing the Manufacturer, how to I get my function to use either query based on the Manufacturer Value being present or not.
The reason is I will have a function which first checks an SKU for a Description, if it is not present – it uses this method to get a Description from a Similar Product, then updates the product being added with the similar product’s description.

Here is the function so far:

ALTER FUNCTION [dbo].[GetDescriptionByTitleManufacturer]
(   
    @Title varchar(400),
    @Manufacturer varchar(160)
)
RETURNS TABLE 
AS
RETURN (
    SELECT TOP 100 PERCENT SKU, Description, LEN(CONVERT(VARCHAR
    (1000),Description)) AS LenDesc FROM tblItem
    WHERE Title = @Title AND Manufacturer = @Manufacturer
    ORDER BY LenDesc DESC
    )

I’ve tried adding BEGINs and IF…ELSEs but get errors or syntax problems each way I try it, I want to be able to do something like this pseudo-function (which does not work):

ALTER FUNCTION [dbo].[GetDescriptionByTitleManufacturer]
(   
    @Title varchar(400),
    @Manufacturer varchar(160)
)
RETURNS TABLE 
AS
BEGIN
IF (@Manufacturer = Null)
RETURN (
    SELECT TOP 100 PERCENT SKU, Description, LEN(CONVERT(VARCHAR
    (1000),Description)) AS LenDesc FROM tblItem
    WHERE Title = @Title ORDER BY LenDesc DESC
    )
ELSE
RETURN (
    SELECT TOP 100 PERCENT SKU, Description, LEN(CONVERT(VARCHAR
    (1000),Description)) AS LenDesc FROM tblItem
    WHERE Title = @Title AND Manufacturer = @Manufacturer
    ORDER BY LenDesc DESC
    )

END

  • 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-14T04:51:25+00:00Added an answer on May 14, 2026 at 4:51 am

    Could you do something like this?

    ALTER FUNCTION [dbo].[GetDescriptionByTitleManufacturer]
    (   
        @Title varchar(400),
        @Manufacturer varchar(160)
    )
    RETURNS TABLE 
    AS
    RETURN (
        SELECT TOP 100 PERCENT SKU, Description, LEN(CONVERT(VARCHAR
        (1000),Description)) AS LenDesc FROM tblItem
        WHERE Title = @Title AND (@Manufacturer IS NULL OR Manufacturer = @Manufacturer)
        ORDER BY LenDesc DESC
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be easy, but I cannot seem to get it right as I
This function keeps giving me problem I cannot seem to find the right combination
I need a function just like preg_replace but instead of strings I need it
I'm in a need to optimize this really tiny, but pesky function. unsigned umod(int
I'll just get right into it. I have a class User that needs to
I just finished writing this script and getting it to work but I need
I am having quite a tricky problem, which i just cannot seem to solve.
I've written this code using various online sources but I cannot seem to figure
I have this code here in PHP using Codeigniter framework, I can't seem to
i need to work with setTimeout function but that function does not work. First

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.