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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:53:04+00:00 2026-05-19T05:53:04+00:00

I am using a Scalar-Valued Function to find out if a user of the

  • 0

I am using a Scalar-Valued Function to find out if a user of the system has images, audio files or videos in their profile.

When I search through members I want to order the members by amount of media they have. So for example a user with all media (videos, audio and images) would get 3, 1 point for each media they have. If they have 2 media(images and video) but no audio they would get 2. This would be listed after all the users that have all 3 media.

The stored procedure has this:

SELECT
a.MemberID,
a.UserName,
a.LastLogin,
a.City,
b.Abbr,
c.Country,
a.AvatarMed,
a.Gender,
sbuser.sf_MemberHasImages(a.MemberID),
sbuser.sf_MemberHasVideo(a.MemberID),
sbuser.sf_MemberHasAudio(a.MemberID),
d.Domain,
sbuser.sf_DisplayName(a.MemberID),
a.CreateDate,
a.Claimed,
a.ProfileTypeID,
a.Zip,
a.PhoneNbr,
a.PrPhone
FROM Member a
LEFT JOIN State b ON b.StateID = a.StateID
INNER JOIN Country c ON c.countryID = a.CountryID
INNER JOIN Region d ON d.RegionID = a.MemberREgionID
WHERE ProfileTypeID IS NOT NULL
AND (sbuser.sf_DisplayName(a.MemberID) LIKE @UserName + '%')
AND a.MemberID <> @MemberID
ORDER BY a.Claimed DESC, a.AvatarTiny DESC, sbuser.sf_MemberHasMedia(a.MemberID)

If you note the order by, it contains the following:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [sbuser].[sf_MemberHasMedia](@MemberID bigint)

RETURNS BIT
AS
BEGIN
DECLARE @OUTSTR INT
DECLARE @OUT1 BIT
DECLARE @OUT2 BIT
DECLARE @OUT3 BIT
SET @OUT1 = (SELECT CAST(COUNT(MemberAudioID) AS BIT) FROM MemberAudio
WHERE MemberID @MemberID)
RETURN @OUTSTR = @OUT1
END

RETURNS BIT
AS
BEGIN
SET @OUT2 = (SELECT CAST(COUNT(a.MemberImgID) AS BIT)
From MemberImg a
INNER JOIN MemberImgGallery b ON b.MemberImgGalleryID=a.MemberImgGalleryID
WHERE b.MemberID = @MemberID)
RETURN @OUTSTR = @OUTSTR + @OUT2
END

RETURNS BIT
AS
BEGIN
SET @OUT3 = (SELECT CAST(COUNT(MemberVideoID) AS BIT) FROM MemberVideo
WHERE MemberID = @MemberID)
RETURN @OUTSTR = @OUTSTR + @OUT3
END

I am lost in the logic of this, and it should be easy. Any help would be greatly appreciated.

Many thanks,
Paul

  • 1 1 Answer
  • 1 View
  • 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-19T05:53:06+00:00Added an answer on May 19, 2026 at 5:53 am

    I’ve attempted to clean the syntax of the function up a little. The key point is that the return type of the function should be an INT instead of a BIT.

    ALTER FUNCTION [sbuser].[sf_MemberHasMedia](@MemberID bigint)
    
    RETURNS INT
    AS
    BEGIN
        DECLARE @OUTSTR INT
        DECLARE @OUT1 INT
        DECLARE @OUT2 INT
        DECLARE @OUT3 INT
    
        SET @OUT1 = (SELECT CAST(COUNT(MemberAudioID) AS BIT) 
                     FROM MemberAudio
                     WHERE MemberID @MemberID)
    
        SET @OUT2 = (SELECT CAST(COUNT(a.MemberImgID) AS BIT)
                     FROM MemberImg a
                         INNER JOIN MemberImgGallery b 
                             ON b.MemberImgGalleryID=a.MemberImgGalleryID
                     WHERE b.MemberID = @MemberID)
    
        SET @OUT3 = (SELECT CAST(COUNT(MemberVideoID) AS BIT) 
                     FROM MemberVideo
                     WHERE MemberID = @MemberID)
    
        SET @OUTSTR = @OUT1 + @OUT2 + @OUT3
        RETURN @OUTSTR
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scalar-valued function called DATEONLY that returns DATEADD(DD,0, DATEDIFF(DD,0, @DATETIME)), just like
I am trying to avoid using a scalar valued functions in my project, so
I have a Scalar-valued function in my DB: ALTER FUNCTION [dbo].[fx_fooFunct] (@MyParam varchar(max)) RETURNS
Using File::Find , how can I pass parameters to the function that processes each
I'm using opencv2 c++ interface. I want to understand how convert color from Scalar
Using a __set accessor function in PHP I can set the value of a
I'm trying to write a function in matlab for averaging images (all of the
Im using scala Map#get function, and for every accurate query it returns as Some[String]
I am trying to use Scala to find the parameter to a function that
In Matlab documentation for function fminsearch(fun,x0) , x0 can be a scalar, vector, or

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.