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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:00:02+00:00 2026-06-06T06:00:02+00:00

Please suppose that in SQL Server 2005, if you launch the following query: SELECT

  • 0

Please suppose that in SQL Server 2005, if you launch the following query:

SELECT CHICKEN_CODE FROM ALL_CHICKENS WHERE MY_PARAMETER = 'N123123123';

you obtain:

31

as result.

Now, I would like to write a function that, given a value for MY_PARAMETER, yields the corresponding value of CHICKEN_CODE, found in the table ALL_CHICKENS.

I have written the following stored function in SQL Server 2005:

ALTER FUNCTION [dbo].[determines_chicken_code]
(
    @input_parameter                         VARCHAR 
)
RETURNS varchar
AS 
BEGIN
    DECLARE @myresult varchar

    SELECT @myresult  =  CHICKEN_CODE
    FROM dbo.ALL_CHICKENS
    WHERE MY_PARAMETER = @input_parameter

    RETURN @myresult
END

But if I launch the following query:

SELECT DBO.determines_chicken_code('N123123123') 

it yields:

NULL

Why?

Thank you in advance for your kind cooperation.

  • 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-06-06T06:00:04+00:00Added an answer on June 6, 2026 at 6:00 am

    define the length of your varchar variables like this

    varchar(100)
    

    Without the 100 (or whatever length you choose) its lengh is 1 and the where clause will filter out the correct results.

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

Sidebar

Related Questions

Suppose, I am about to start a project using ASP.NET and SQL Server 2005.
I have a SQL Server 2005 database that I'm trying to access as a
[Please note that this is a different question from the already answered How to
Suppose we want to select the data from the database then we write the
I have connected my C# winforms app to SQL Server 2005 where is a
I was previously using a database in SQL Server CE . That's kind of
sql select in relation many-to-many not works as expected i have the following tables
I use C#. I fill a dataset with the result of sql query. Suppose
I have 2 tables in SQL Server 2005 db with structures represented as such:
I have a table in SQL server that has the normal tree structure of

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.