Forum Replies Created

Viewing 15 posts - 31 through 45 (of 46 total)

  • RE: formatting variable output

    What does the source data look like?

  • RE: How can I add Number at the end?

    BTW, I was using 5409045121009 table structure. Also I didnt put in the leading zeros but that would be easy enough if you need it.

  • RE: How can I add Number at the end?

    One more solution using derived table

    update t1

    set somethingiwant = t2.somethingiwant

    from test as t1

    join(SELECTid,

    code+CAST((select count(*)

    from test b

    where a.code = b.code

    and a.id >=b.id)

    as varchar(10)) as somethingiwant

    from test a

    )as t2

    on t1.id = t2.id

    ...

  • RE: Dymanic database context change

    I noticed you mentioned sysfiles in your earlier post. Usually stored procedures created in master and prefixed with sp_ will run in the context of the database they are called...

  • RE: Populate a Table Variable Dynamic SQL results?

    Yes, if the dynamic sql is set based then you will need to put it into a temp table to be able to work with the data. If all you...

  • RE: Is NULL comparison slow?

    Ahhh, I didn't look at your code that closely. Now I see what you were talking about.

  • RE: Is NULL comparison slow?

    Antares answered the coalesce question.

    Antares,

    In the original query, rows with a NULL ErrorID would not have been returned if his @ErrNumStart was not null.

    It would have evaluated...

  • RE: Is NULL comparison slow?

    Have you tried using a coalesce with a number that isn't valid for the variable like a negative number. e.g

    AND(ErrorID >= COALESCE(@errNumStart,-1))

  • RE: Populate a Table Variable Dynamic SQL results?

    That will work just fine, but the variables scope is in the exec statment and it will go away as soon as it completes. You will not be able to...

  • RE: Dymanic database context change

    That still does not change the database context except for during the exec statement.

  • RE: Dymanic database context change

    The use is only for the duration of the execution.

    You can see that by running this

    declare @db nvarchar(50)

    declare @db2 nvarchar(50)

    set @db = 'use tempdb select db_name()'

    set @db2 = 'select...

  • RE: Populate a Table Variable Dynamic SQL results?

    You can't. I'm pretty sure since I said that someone on here will figure out a way.

  • RE: help with complex query/results

    You really dont have to loop although you do have to build dynamic sql.

    Here is an example.

    CREATE TABLE Tests (name varchar(50))

    GO

    INSERT INTO Tests

    SELECT 'Test1'

    GO

    INSERT INTO Tests

    SELECT 'Test2'

    GO

    INSERT INTO Tests

    SELECT...

  • RE: Exec not right in stored procedure?

    This works... Notice how I doubled up on the single quotes. I think that may be your problem.

    CREATE TABLE test (col1 char(1), col2 char(1))

    go

    CREATE PROC test_it @sqlVals varchar(10)

    as

    ...

  • RE: how would You determine the fields in a PK?

    Here is a view I created similar to Antares without the huge IN clause...

    It does require a numbers (sequence) table though.

    CREATE VIEW dbo.PK_Columns_View

    AS

    selecto.nameASname,

    o.idASid,

    c.nameAScolumn_name,

    n.idASsequence_number

    FROMsysobjectsASo

    JOINsysindexesASi

    ONo.id =...

Viewing 15 posts - 31 through 45 (of 46 total)