Forum Replies Created

Viewing 15 posts - 211 through 225 (of 568 total)

  • RE: Sum(A) by B but use the first row for C?

    Check with these statements, is any performance cross, you update last column in the separate statement.

    select a.userid , sum(a.Num1)

    ,(select top 1 b.Num2 from Tmp b where b.userid =...

  • RE: update row multiple times using single update statement

    txp001 (10/11/2009)


    on t1.a = t2.a

    The conditions matches the first row in the t2, so that it’s update/ compare the first row data,

    Just assumption of update t1 table column-b with...

  • RE: Date and Time Issues

    webnoel (10/11/2009)


    1900-01-01 15:30:00.000

    I need it without the Micro seconds.

    To get the exact result use the smalldatetime.

    declare @date datetime

    set @date = getdate()

    SELECT @date = cast(DATEADD(D, DATEDIFF(D, @date, 0), @date) as...

  • RE: case in where condition

    01)

    select id from sale_Invoice

    where invoiceDate <= @OnDate

    and invoiceDate >= isnull(@OBDate,invoiceDate)

    02)

    select id from sale_Invoice

    where invoiceDate<=@OnDate

    and invoiceDate >= case when @OBDate is null then invoiceDate else @OBDate end

    03)

    declare

  • RE: Having and Max of a column

    create table #temp

    (

    col1 varchar(10),

    col2 varchar(10),

    col3 varchar(10),

    col4 varchar(10),

    col5 int

    )

    insert into #temp

    select 'A','AA','AAA','KA',10

    union all

    select 'A','AA','AAA','KB',20

    union all

    select 'A','AA','AAA','KC',30

    union all

    select 'B','BB','BBB','LB',40

    union all

    select 'B','BB','BBB','LC',50

    union all

    select 'B','BB','BBB','LD',60

    select a.col1,a.col2,a.col3,a.col4,a.col5

    from #temp a,

    (

    select a.col1,a.col2,a.col3,max(a.col5)col5

    from #temp a

    group by a.col1,a.col2,a.col3

    )...

  • RE: Get records with maximum date only

    select a.studentID,a.certID,a.issuedate

    from scenario a,

    (

    select studentID,max(issuedate)issuedate

    from scenario

    group by studentID

    )as b

    where a.studentID = b.studentID

    and a.issuedate = b.issuedate

    order by a.studentID

  • RE: Creative solution for modifying/ALTER VIEW

    SELECT * FROM VW_SLS

    UNION ALL

    SELECT * FROM SLS_CURRENT_MONTH

    For the permanent scenario, alter the view table.

  • RE: Having and Max of a column

    Hi,

    just try with

    select colA,colB,colC,max(ColF)

    from mytable

    group by colA,colB,colC

  • RE: patindex problem

    declare @result varchar(50)

    set @result = 'ssf/sdf/sdf/sf/sf/sf/10/2009'

    select replace(@result,'/2009','')

    /*ssf/sdf/sdf/sf/sf/sf/10*/

    select reverse(replace(@result,'/2009',''))

    /*01/fs/fs/fs/fds/fds/fss*/

    select patindex('%/%',reverse(replace(@result,'/2009','')))

    /*3*/

    select left(reverse(replace(@result,'/2009','')),(patindex('%/%',reverse(replace(@result,'/2009',''))))-1)

    /*01*/

    select reverse (left(reverse(replace(@result,'/2009','')),(patindex('%/%',reverse(replace(@result,'/2009',''))))-1))

    /*10*/

  • RE: t-sql - database name

    select db_name()

  • RE: patindex problem

    declare @result varchar(50)

    set @result = 'dat1/dat2/dat/sd34/dat4/3/2009'

    select @result = replace(right(@result,6),'/2009','')

    select @result

  • RE: Inserting TAB into string

    RD-201664 (10/6/2009)


    select 'there should be a tab between here' + char(9) + 'and here'

    Ideas?

    declare @result varchar(100)

    set @result = 'TEST START'+char(9)+'EXEC'+char(9)+'TEST END'

    select @result

    RESULT

    TEST STARTEXECTEST END

    set @result = replace(@result,char(9),' -TAB HERE- ')

    select...

  • RE: Dynamic Column Names with sp_executesql

    declare @cols as nvarchar(50)

    declare @tables as nvarchar(50)

    set @cols = 'Name'

    set @tables = 'Bank'

    if object_id(@tables)>0

    begin

    if (COLUMNPROPERTY( OBJECT_ID(@tables),@cols,'PRECISION'))>0

    begin

    select 'PASS'-- your execution statement

    end

    else

    begin

    select 'Column Fail'

    end

    end

    else

    select 'Table Fail'

  • RE: Dynamic Column Names with sp_executesql

    declare @cols as nvarchar(50)

    declare @col_name as nvarchar(50)

    declare @tables as nvarchar(50)

    declare @sql as nvarchar(300)

    set @cols = 'Name'--original column name

    set @tables = 'Bank'

    set @col_name = 'NAME123'-- display column name

    set...

  • RE: Dynamic Column Names with sp_executesql

    declare @cols as nvarchar(50)

    declare @tables as nvarchar(50)

    declare @sql as nvarchar(300)

    set @cols = 'Name'

    set @tables = 'Bank'

    set @sql = N'SELECT '+ @cols +' FROM ' + @tables...

Viewing 15 posts - 211 through 225 (of 568 total)