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

  • Home
  • SEARCH
  • 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 7902991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:38:40+00:00 2026-06-03T09:38:40+00:00

With regards to this question here SQL CLR return two new columns I am

  • 0

With regards to this question here SQL CLR return two new columns I am trying to create a simple SQL CLR function, where I can pass two strings into the function and it passes me back two NEW columns.

So say I have the following data:-

Col A     Col B
Bob       Joe
Jane      John

I want to be able to pass Col A and Col B to a CLR function and have it return something like this (whereby Col C and D are new columns):-

Col A     Col B     Col C     Col D
Bob       Joe       BobCLR    JoeCLR
Jane      John      JaneCLR   JohnCLR

I have the following code:-

 [SqlFunction(FillRowMethodName = "FillRow")]
    public static IEnumerable MyCLRFunction(string A, string B)
    {
        String[] values = new String[2];
        values[0] = A+"CLR";
        values[1]= B+"CLR";

        return values;
    }

         private static void FillRow(Object obj, out string C, out string D)
      {
            String[] row = (object[])obj;
            C = (string)row[0];
            D = (string)row[1];
      }

I can register the assembly in SQL Server ok using CREATE ASSEMBLY

I can create the function ok in SQL Server as follows:-

CREATE FUNCTION dbo.MyCLRFunction(@a [nvarchar](4000), @b [nvarchar](4000))
RETURNS TABLE
(c [nvarchar](4000) null, d [nvarchar](4000) null) with execute as caller
AS
EXTERNAL NAME [MyNamespace].[CLRFunctions].[MyCLRFunction]

However when I do:-

SELECT * FROM MyCLRFunction('Bob','Joe')

Im getting:-

Msg 6260, Level 16, State 1, Line 1
An error occurred while getting new row from user defined Table Valued Function : 
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.String[]'.
System.InvalidCastException: 
   at CLRFunctions.FillRow(Object obj, String& C, String& D)
  • 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-03T09:38:41+00:00Added an answer on June 3, 2026 at 9:38 am

    Ok have managed to do this now using a KeyValuePair within an Ienumerable.

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data.SqlTypes;
    using Microsoft.SqlServer.Server;
    
    public class CLRFunctions
    {
    
        private static IEnumerable<KeyValuePair<double, double>> CoordinatesEnumerable(double Lat, double Long)
        {
            return new Dictionary<double, double> { { Lat, Long } };
        }
    
        [SqlFunction(FillRowMethodName = "FillRow")]
        public static IEnumerable ToLatLong(double East, double North)
        {
            return CoordinatesEnumerable(East, North);
        }
    
        private static void FillRow(Object obj, out SqlDouble Lat, out SqlDouble Long)
        {
            KeyValuePair<double, double> Coordinates = (KeyValuePair<double, double>)obj;
            Lat = new SqlDouble(Coordinates.Key);
            Long = new SqlDouble(Coordinates.Value);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty sure this is a simple question in regards to formatting but here's
I am trying to create a function that can subtract between 2 dates but
This is mainly in regards to my question here , but I don't understand
I was looking at this question Here in regards to this library. However it
This question is in regards to this blog entry. https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/ All the way at
I have just asked this question an hour ago but with regards to IE8
I had posted a question in regards to this code. I found that JTextArea
I bumped into an additional question that I needed in regards to this: Using
I have few question in this regard When you create an internet page, does
I have a question here.I better paste my code first SET @Sql = 'DECLARE

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.