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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:16:37+00:00 2026-06-07T17:16:37+00:00

With this SQL snippet from my SPROC: — Having the PanelPayout role gives you

  • 0

With this SQL snippet from my SPROC:

            -- Having the PanelPayout role gives you more transaction types to look for, hence the CASE statement.
            CASE WHEN EXISTS (SELECT RoleID FROM aspnet_UsersInRoles ur WHERE ur.RoleID = 'DEDCD456-A25A-43C5-8125-A1D1223B19EC' AND ur.UserID = s.aspnet_UserID) THEN
                (SELECT ISNULL(SUM(Amount), 0) FROM TransactionsLog payouts WHERE 
                    payouts.StaffID = s.ID 
                    AND payouts.TransactionType IN (48, 49, 3, 16, 292, 293)
                    AND (payouts.OrderDate >= dbo.Date(@date) AND payouts.OrderDate <= dbo.EndOfDay(@date))
                    AND @shift = CASE @shift WHEN 0 THEN 0 ELSE dbo.GetShiftByDate(payouts.OrderDate) END
                ) 
            ELSE
                (SELECT ISNULL(SUM(Amount), 0) FROM TransactionsLog payouts WHERE 
                    payouts.StaffID = s.ID 
                    AND payouts.TransactionType IN (48, 49, 3) 
                    AND (payouts.OrderDate >= dbo.Date(@date) AND payouts.OrderDate <= dbo.EndOfDay(@date))
                    AND @shift = CASE @shift WHEN 0 THEN 0 ELSE dbo.GetShiftByDate(payouts.OrderDate) END
                ) 
            END     

And this works fine. However, overall, the query is not returning what I want due to some issues in how the database was originally structured 7 years ago. So, I’m going to use C# to do what I need to do. My question is can a UDF return a list of ints that could be used with IN, so I would only need to write

                (SELECT ISNULL(SUM(Amount), 0) FROM TransactionsLog payouts WHERE 
                    payouts.StaffID = s.ID 
                    AND payouts.TransactionType IN dbo.PayoutTransactionsValidForStaff(s.ID)
                    AND (payouts.OrderDate >= dbo.Date(@date) AND payouts.OrderDate <= dbo.EndOfDay(@date))
                    AND @shift = CASE @shift WHEN 0 THEN 0 ELSE dbo.GetShiftByDate(payouts.OrderDate) END
                ) 

where PayoutTransactionsValidForStaff(s.ID) would return the list of ints needed to check? I would imagine it could be a table-valued function, but I don’t have time to test because I gotta get this update shipped. Just wondering if anyone knew off the top of their head. 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-06-07T17:16:40+00:00Added an answer on June 7, 2026 at 5:16 pm

    Yes, you can create a table valued function in SQL which returns a table instead of a scalar result. You can use the result of this in a Sql in statement

    http://msdn.microsoft.com/en-us/library/ms191165(v=sql.105).aspx

    CREATE FUNCTION dbo.Test()
    RETURNS @funcTable TABLE 
    (
        -- Columns returned by the function
        ID int PRIMARY KEY NOT NULL    
    )
    AS 
    -- Return some arbitrary ints
    BEGIN
        INSERT @funcTable VALUES (1)
        INSERT @funcTable VALUES (2)
    
        RETURN 
    END
    
    GO
    
    -- Test it - insert 1,2,3 into a table var
    DECLARE @SomeTable table (ID int)
    INSERT INTO @SomeTable VALUES (1)
    INSERT INTO @SomeTable VALUES (2)
    INSERT INTO @SomeTable VALUES (3)
    
    -- Select from @SomeTable where the ID is in the result of the UDF
    select * from @SomeTable WHERE ID IN (SELECT ID FROM dbo.Test())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This SQL statement SELECT `ip`, `when` FROM `metrics` WHERE `vidID` = '1' GROUP BY
Given this SQL: SELECT * FROM mytable ORDER BY mycolumn, RAND() Assuming that mycolumn
i have this sql query select * from table where name like ? but
I have this SQL statement: SELECT * FROM history WHERE (fk_person = 2119) AND
I have to migrate this query (simplified here) from T-SQL to ORACLE SET IDENTITY_INSERT
I found this snippet of SQL in a view and I am rather puzzled
This is a snippet of my SQL cursor, which works fine. But I now
This question concerns generics and types as well as datatables. The following snippet is
This is a snippet of text from the source xml document: Great Lakes. The
Given following snippet (MS SQL): DECLARE UpdateList CURSOR FOR SELECT MyColumn FROM MyTable OPEN

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.