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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:19:06+00:00 2026-06-17T23:19:06+00:00

I have the below Query that returns the information that I need, but I

  • 0

I have the below Query that returns the information that I need, but I need to use this query In a Scalar Valued function to use the returned values in a computed column.

The XML Column is in the same table and I need to insert the values from Settings into a column named Directions

;WITH XMLNAMESPACES ( 'http://www.w3.org/2001/XMLSchema' AS als )
SELECT
 a.a.value('@Settings', 'VARCHAR(50)') AS [Settings]

FROM Base AS X
    CROSS APPLY X.BaseXML.nodes('als:Name') a(a)

The Function I was trying, but not getting anywhere was

CREATE FUNCTION [dbo].[ChooseRevision](@lineId int) Returns integer As
Begin
Return (WITH XMLNAMESPACES ( 'http://www.w3.org/2001/XMLSchema' AS als )
SELECT
 a.a.value('@Settings', 'VARCHAR(50)') AS [Settings]

FROM Base AS X
    CROSS APPLY X.BaseXML.nodes('als:Name') a(a)
Where LineId = @lideid
)
End

GO

How would you include the query inside a scarlar function to use as a computed column?

<als:Doc xmlns:als="http://www.w3.org/2001/XMLSchema" SchemaVersion="0.1" Settings="First Test" Title="Recovery Loop">
  <als:Base Rev="0" Id="201" />
  <als:Number TimeStamp="2013-01-21T15:08:00">
    <als:Member Name="Club Run" DirId="123" />
  </als:Number>
  </als:Doc>
  • 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-17T23:19:07+00:00Added an answer on June 17, 2026 at 11:19 pm

    Assuming there is only one als:Name node per XML value you can write this:

    CREATE FUNCTION [dbo].[ChooseRevision](@lineId int) 
    RETURNS VARCHAR(50) 
    AS
    BEGIN
      DECLARE @r VARCHAR(50);
      WITH XMLNAMESPACES('http://www.w3.org/2001/XMLSchema' AS als)
      SELECT
       @r = BaseXML.value('als:Doc[1]/@Settings', 'VARCHAR(50)') 
      FROM Base
      WHERE LineId = @lineId;
      RETURN @r;
    END
    

    If you are planning to use this function within the dbo.Base table itself, you should use this version instead:

    CREATE FUNCTION [dbo].[ChooseRevision](@xml XML) 
    RETURNS VARCHAR(50) 
    AS
    BEGIN
      DECLARE @r VARCHAR(50);
      WITH XMLNAMESPACES('http://www.w3.org/2001/XMLSchema' AS als)
      SELECT @r = @xml.value('als:Doc[1]/@Settings', 'VARCHAR(50)') 
      RETURN @r;
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that returns a result set similar to the one below:
I'm using Sql-Server, and I have the below query which returns all columns that
The query below returns rows that have both loginid and ip2 in the bumps
I have a query below that I use to retrieve the records not updated
I have two tables described below. What I need is a single query that
I have a Linq query that returns an anonymous type, which I then use
I have a long running query that returns a large data set. This query
I have a query that returns a result set similar to the one below
I have below a working query that needs to be simplified. The reason is
I have the query below that when run it says that 325 rows were

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.