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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:31:41+00:00 2026-05-28T04:31:41+00:00

I’m now all day on a fairly simple udf. It’s below. When I paste

  • 0

I’m now all day on a fairly simple udf. It’s below. When I paste the select statement into a query, it runs as expected… when I execute the entire function, I get “0” every time. As you know there aren’t a ton of debugging options, so it’s hard to see what value are/ aren’t being set as it executes. The basic purpose of it is to make sure stock data exists in a daily pricing table. So I can check by how many days’ data I’m checking for, the ticker, and the latest trading date to check. A subquery gets me the correct trading dates, and I use “IN” to pull data out of the pricing and vol table… if the count of what comes back is less than the number of days I’m checking, no good. If it does, we’re in business. Any help would be great, I’m a newb that is punting at this point:

ALTER FUNCTION dbo.PricingVolDataAvailableToDateProvided
    (@Ticker char,
     @StartDate DATE,
     @NumberOfDaysBack int)
    RETURNS bit
AS
    BEGIN

    DECLARE @Result bit
    DECLARE @RecordCount int

SET @RecordCount = (
    SELECT COUNT(TradeDate) AS Expr1
    FROM   (SELECT TOP (100) PERCENT TradeDate
            FROM   tblDailyPricingAndVol
            WHERE  ( Symbol = @Ticker )
                   AND ( TradeDate IN (SELECT TOP (@NumberOfDaysBack)
                                      CAST(TradingDate AS DATE) AS Expr1
                                       FROM   tblTradingDays
                                       WHERE  ( TradingDate <= @StartDate )
                                       ORDER  BY TradingDate DESC) )
            ORDER  BY TradeDate DESC) AS TempTable ) 

    IF @RecordCount = @NumberOfDaysBack
        SET @Result = 1
    ELSE
        SET @Result = 0

    RETURN @Result

    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-28T04:31:42+00:00Added an answer on May 28, 2026 at 4:31 am

    @Ticker char seems suspect.

    If you don’t declare a length in the parameter definition it defaults to char(1) so quite likely your passed in tickers are being silently truncated – hence no matches.

    SELECT TOP (100) PERCENT TradeDate ... ORDER  BY TradeDate DESC
    

    in the derived table is pointless but won’t affect the result.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.