Click here to Skip to main content
15,926,062 members
Home / Discussions / Database
   

Database

 
GeneralRe: Help with recordsets: How to get the value of a primary key? Pin
Daniel Turini16-Oct-02 5:39
Daniel Turini16-Oct-02 5:39 
GeneralRe: Help with recordsets: How to get the value of a primary key? Pin
Nick Parker16-Oct-02 5:44
protectorNick Parker16-Oct-02 5:44 
AnswerRe: Help with recordsets: How to get the value of a primary key? Pin
Richard Deeming17-Oct-02 23:58
mveRichard Deeming17-Oct-02 23:58 
GeneralMSDE - localhost Pin
Andy H15-Oct-02 12:52
Andy H15-Oct-02 12:52 
GeneralRe: MSDE - localhost Pin
Russell Morris15-Oct-02 16:13
Russell Morris15-Oct-02 16:13 
GeneralRe: MSDE - localhost Pin
Steve S15-Oct-02 23:43
Steve S15-Oct-02 23:43 
GeneralTable Variables as Stored Procedure Parameters Pin
Alex Deem15-Oct-02 6:47
Alex Deem15-Oct-02 6:47 
GeneralRe: Table Variables as Stored Procedure Parameters Pin
Richard Deeming18-Oct-02 0:13
mveRichard Deeming18-Oct-02 0:13 
This code came from one of the SQL Server sites:
CREATE FUNCTION fn_Split
    (
        @sText 	 varchar(8000), 
        @sDelim  varchar(20) = ' '
    )
RETURNS @retArray TABLE 
    (
        idx smallint Primary Key, 
        value varchar(8000)
    )
AS
BEGIN
DECLARE @idx smallint,
    @value varchar(8000),
    @bcontinue bit,
    @iStrike smallint,
    @iDelimlength tinyint
 
    SELECT
        @idx = 0,
        @bContinue = 1,
        @sText = LTrim(RTrim(@sText)),
        @iDelimLength = CASE
            WHEN @sDelim Is Null THEN 0
            WHEN @sDelim = 'Empty' THEN 0
            WHEN @sDelim = 'Space' THEN 1
            ELSE DataLength(@sDelim)
        END,
        @sDelim = CASE
            WHEN @sDelim Is Null THEN ''
            WHEN @sDelim = 'Empty' THEN ''
            WHEN @sDelim = 'Space' THEN ' '
            ELSE @sDelim
        END
 
 
    IF NOT (@iDelimlength = 0)
    BEGIN
        WHILE @bcontinue = 1
        BEGIN
--If you can find the delimiter in the text, retrieve the first element and
--insert it with its index into the return table.
 
            IF CHARINDEX(@sDelim, @sText)>0
            BEGIN
                SET @value = LTrim(RTrim(SUBSTRING(@sText,1,CHARINDEX(@sDelim,@sText)-1)))
 
                INSERT INTO @retArray (idx, value)
                VALUES (@idx, @value)
 
--Trim the element and its delimiter from the front of the string.
--Increment the index and loop.
                SELECT
                    @idx = @idx + 1,
                    @iStrike = DATALENGTH(@value) + @iDelimlength,
                    @sText = LTrim(RTrim(Right(@sText,DATALENGTH(@sText) - @iStrike)))
            END
            ELSE
            BEGIN
--If you can’t find the delimiter in the text, @sText is the last value in
--@retArray.
                SET @value = LTrim(RTrim(@sText))
                INSERT INTO @retArray (idx, value)
                VALUES (@idx, @value)
--Exit the WHILE loop.
                SET @bcontinue = 0
            END
        END
    END
    ELSE
    BEGIN
        WHILE @bcontinue=1
        BEGIN
--If the delimiter is an empty string, check for remaining text
--instead of a delimiter. Insert the first character into the
--retArray table. Trim the character from the front of the string.
--Increment the index and loop.
            IF DATALENGTH(@sText)>1
            BEGIN
                SET @value = SUBSTRING(@sText,1,1)
                INSERT INTO @retArray (idx, value)
                VALUES (@idx, @value)
 
                SELECT
                    @idx = @idx+1,
                    @sText = SUBSTRING(@sText,2,DATALENGTH(@sText)-1)
 
            END
            ELSE
            BEGIN
--One character remains.
--Insert the character, and exit the WHILE loop.
                INSERT INTO @retArray (idx, value)
                VALUES (@idx, @sText)
                SET @bcontinue = 0	
            END
        END
    END
 
    RETURN
END

You can pass a list of values separated by commas to your proc, call this function to get a table, and then cast the table values to the type you need. E.g.:
Create Proc dbo.spSetBillingPlan_Custom
(
    @ContractNumber int,
    @PhaseNum       varchar(8000),
    @Perc           varchar(8000)
)
As
DECLARE @ArgTable TABLE(PhaseNum int, Perc decimal(5,4))
    INSERT INTO 
        @ArgTable (PhaseNum, Perc)
    SELECT
        CAST(PhaseNum.value As int),
        CAST(Perc.value As decimal(5,4))
    FROM
        dbo.fn_Split(@PhaseNum, ',') As PhaseNum
        INNER JOIN
        dbo.fn_Split(@Perc, ',') As Perc
        On PhaseNum.idx = Perc.idx
 
    --yadda yadda yadda

GeneralRe: Table Variables as Stored Procedure Parameters Pin
Morten Abrahamsen22-Oct-02 2:14
Morten Abrahamsen22-Oct-02 2:14 
GeneralSQL equivalent of Access Memo feild Pin
Ray Cassick15-Oct-02 2:19
Ray Cassick15-Oct-02 2:19 
GeneralRe: SQL equivalent of Access Memo feild Pin
Paul Watson15-Oct-02 3:17
sitebuilderPaul Watson15-Oct-02 3:17 
GeneralRe: SQL equivalent of Access Memo feild Pin
Jon Hulatt15-Oct-02 3:59
Jon Hulatt15-Oct-02 3:59 
GeneralRe: SQL equivalent of Access Memo feild Pin
Paul Watson15-Oct-02 4:51
sitebuilderPaul Watson15-Oct-02 4:51 
GeneralRe: SQL equivalent of Access Memo feild Pin
Jon Hulatt15-Oct-02 5:07
Jon Hulatt15-Oct-02 5:07 
GeneralRe: SQL equivalent of Access Memo feild Pin
Ray Cassick15-Oct-02 4:35
Ray Cassick15-Oct-02 4:35 
GeneralRe: SQL equivalent of Access Memo feild Pin
Paul Watson15-Oct-02 4:57
sitebuilderPaul Watson15-Oct-02 4:57 
GeneralRe: SQL equivalent of Access Memo feild Pin
Jon Hulatt15-Oct-02 5:12
Jon Hulatt15-Oct-02 5:12 
GeneralRe: SQL equivalent of Access Memo feild Pin
William Forney15-Oct-02 6:25
William Forney15-Oct-02 6:25 
GeneralRe: SQL equivalent of Access Memo feild Pin
Jon Hulatt15-Oct-02 6:35
Jon Hulatt15-Oct-02 6:35 
GeneralCase Sensitive Comparison Method Pin
Kerry Chou14-Oct-02 16:07
Kerry Chou14-Oct-02 16:07 
GeneralRe: Case Sensitive Comparison Method Pin
Jon Hulatt14-Oct-02 22:03
Jon Hulatt14-Oct-02 22:03 
GeneralRe: Case Sensitive Comparison Method Pin
Rein Hillmann14-Oct-02 22:37
Rein Hillmann14-Oct-02 22:37 
QuestionFast Insert ? Pin
ssirisha14-Oct-02 9:00
ssirisha14-Oct-02 9:00 
AnswerRe: Fast Insert ? Pin
Daniel Turini15-Oct-02 1:53
Daniel Turini15-Oct-02 1:53 
GeneralRe: Fast Insert ? Pin
Morten Abrahamsen22-Oct-02 2:19
Morten Abrahamsen22-Oct-02 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.