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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:31:15+00:00 2026-05-26T03:31:15+00:00

Can I get some help, I am trying to avoid dynamic sql, the dynamic

  • 0

Can I get some help, I am trying to avoid dynamic sql, the dynamic sql works but its there any other way to build this without dynamic sql, I am trying a lot of stuff but getting errors, your help will be appreciated.

declare @strSQL varchar(8000)

set @strSQL = 'Select 
ParentFName, ParentLName, ParentMiddleName, 
MailingAddressLine1, MailingAddressLine2, City, State, ZipCode,  
PS.SchoolID, PS.SchoolName, FirstName, LastName, MiddleName, 
CONVERT(varchar(12), SE.Birthday, 101) AS [Birthday], 
SE.GTID, SystemID,Grade, Report_Type, Race, Sex, NON_Funded_Flag, 
DATEDIFF(YY,Birthday , getdate()) -
CASE
WHEN(
  (MONTH(BirthDay)*100 + DAY(BirthDay)) >
  (MONTH(getdate())*100 + DAY(getdate()))
) THEN 1
ELSE 0 END AS Age,
KG, GR01_03, GR04_05, GR06_08_Middle_Grade, GR06_08_middle_school, 
GR09_12, EIP_KG, EIP_01_03,EIP_04_05,LEVEL_1,LEVEL_2,LEVEL_3,LEVEL_4,LEVEL_5,GIFTED, REMEDIAL,VOCATIONAL_HS_LAB, SED, --STUDY_HALL, 
NON_FUNDED, --POST_SECOND_OPTION,
ESOL_ITINERANT, ESOL_NON_ITINERANT, TOTAL_ESOL_SEGMENTS,
FiscalYear, TOTAL_FTE_SEGMENTS, AnnualTuition, 
CONVERT(varchar(12), SE.EnrollmentDate,101) AS [Enrollment Date], 
CONVERT(varchar(12), SE.WithdrawalDate,101) AS [Withdrawal Date],
WD.LookupValueDescription as WithdrawalReason,
FREE_REDUCED_LUNCH, PRIMARY_AREA, GNET_FLAG, 
EstAwardAmount--, previous_year
From 
StudentEnrollment SE 
    inner join (
        select * from openquery([FINANCE], ''select * from scholarship.sp_eligible_students Where Fiscal_Year = ''''' + convert(varchar, @FiscalYear) + ''''' '') ) ES ON
        SE.GTID = ES.GTID Inner Join 
        (select FP.FiscalYear, PrivateSchool.* from PrivateSchool
            INNER JOIN FiscalYearPrivateSchool FP ON PrivateSchool.PrivateSchoolID = FP.PrivateSchoolID AND FP.FiscalYear = ' + @FiscalYear + ') PS 
        ON SE.PrivateSchoolID = PS.PrivateSchoolID AND ES.Fiscal_Year =  PS.FiscalYear Left outer Join 
        vLookUps WD ON SE.WithdrawalreasonId = WD.LookUpID
    WHERE SE.isActive = 1 AND PS.isactive = 1
    AND (' + @SchoolID + ' = -1 or SchoolID = ' + @SchoolID + ' )
    AND (' + @FiscalYear + ' = -1 OR FiscalYear = ' + @FiscalYear + ')
ORDER BY SchoolName, LastName, Firstname, GTID'
--print (@strSQL)
exec (@strSQL)
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-26T03:31:16+00:00Added an answer on May 26, 2026 at 3:31 am
    SET NOCOUNT ON
    
    declare @oq varchar(200)
    
    set @og = 'select * from scholarship.sp_eligible_students Where Fiscal_Year ='+ convert(varchar, @FiscalYear)
    
    select * into #a from openquery([FINANCE], @oq) 
    
    Select  
    ParentFName, ParentLName, ParentMiddleName,  
    MailingAddressLine1, MailingAddressLine2, City, State, ZipCode,   
    PS.SchoolID, PS.SchoolName, FirstName, LastName, MiddleName,  
    CONVERT(varchar(12), SE.Birthday, 101) AS [Birthday],  
    SE.GTID, SystemID,Grade, Report_Type, Race, Sex, NON_Funded_Flag,  
    DATEDIFF(YY,Birthday , getdate()) - 
    CASE 
    WHEN( 
      (MONTH(BirthDay)*100 + DAY(BirthDay)) > 
      (MONTH(getdate())*100 + DAY(getdate())) 
    ) THEN 1 
    ELSE 0 END AS Age, 
    KG, GR01_03, GR04_05, GR06_08_Middle_Grade, GR06_08_middle_school,  
    GR09_12, EIP_KG, EIP_01_03,EIP_04_05,LEVEL_1,LEVEL_2,LEVEL_3,LEVEL_4,LEVEL_5,GIFTED, REMEDIAL,VOCATIONAL_HS_LAB, SED,  
    NON_FUNDED, 
    ESOL_ITINERANT, ESOL_NON_ITINERANT, TOTAL_ESOL_SEGMENTS, 
    FiscalYear, TOTAL_FTE_SEGMENTS, AnnualTuition,  
    CONVERT(varchar(12), SE.EnrollmentDate,101) AS [Enrollment Date],  
    CONVERT(varchar(12), SE.WithdrawalDate,101) AS [Withdrawal Date], 
    WD.LookupValueDescription as WithdrawalReason, 
    FREE_REDUCED_LUNCH, PRIMARY_AREA, GNET_FLAG,  
    EstAwardAmount 
    From  
    StudentEnrollment SE  
        inner join #a ES ON 
            SE.GTID = ES.GTID Inner Join  
            (select FP.FiscalYear, PrivateSchool.* from PrivateSchool 
                INNER JOIN FiscalYearPrivateSchool FP ON PrivateSchool.PrivateSchoolID = FP.PrivateSchoolID AND FP.FiscalYear = @FiscalYear) PS  
            ON SE.PrivateSchoolID = PS.PrivateSchoolID AND ES.Fiscal_Year =  PS.FiscalYear Left outer Join  
            vLookUps WD ON SE.WithdrawalreasonId = WD.LookUpID 
        WHERE SE.isActive = 1 AND PS.isactive = 1 
        AND (@SchoolID = -1 or SchoolID = @SchoolID ) 
        AND (@FiscalYear = -1 OR FiscalYear = @FiscalYear) 
    ORDER BY SchoolName, LastName, Firstname, GTID
    
    drop table #a
    

    If and when this fails. Try fixing it.

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

Sidebar

Related Questions

Is there anything which can help with msmq monitoring? I'd like to get some
Hi and good evening, hope someone can help. I am trying to get some
Can I get some help posting across different pages from a custom control? I've
this is a bit of a newbie question but hoping I can get some
Appreciate if I can get some help writing a LINQ that will get ALL
I need some help trying to come up with a way to set this
I need some help with erb templates, I can't seem to get my head
We'd like to see if we can get some improved performance for analysis and
I'm interested in implementing a Forth system, just so I can get some experience
Can I get some constructive feedback about the following architecture? Simplified Architecture Summary: Return

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.