// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Text.RegularExpressions; using Microsoft.SqlServer.Server; namespace SQLSrvLib { public class MySP1 { [SqlProcedure] public static void MySP() { SqlDataRecord rec = new SqlDataRecord(new SqlMetaData("nummer", SqlDbType.Int), new SqlMetaData("navn", SqlDbType.VarChar, 10), new SqlMetaData("dato", SqlDbType.VarChar, 6)); SqlContext.Pipe.SendResultsStart(rec); using(SqlConnection con = new SqlConnection("context connection=true")) { con.Open(); using(SqlCommand sel = new SqlCommand("SELECT nummer, navn, dato FROM split", con)) { using(SqlDataReader rdr = sel.ExecuteReader()) { while(rdr.Read()) { int nummer = (int)rdr["nummer"]; string navn = (string)rdr["navn"]; string dato = (string)rdr["dato"]; foreach(string datopart in dato.Split(' ')) { rec.SetInt32(0, nummer); rec.SetString(1, navn); rec.SetString(2, datopart); SqlContext.Pipe.SendResultsRow(rec); } } } } } SqlContext.Pipe.SendResultsEnd(); } } }