Forum Replies Created

Viewing 15 posts - 1 through 15 (of 47 total)

  • RE: Convert Rows into Columns

    Here is simple way of getting the output.

    declare @LotNo table (id int identity(1,1),LotNo varchar(50) Null)

    insert into @LotNo

    select 'A'

    union all

    select 'B'

    union all

    Select 'C'

    union all

    select 'D'

    union all

    Select 'E'

    union all

    select 'F'

    union...

  • RE: Recursive query to explode a BOM

    Hi,

    As per your input the other sets should come like

    2000022, 2001770, 2001771

    2000022, 2001527, 2001528

    Above result set dosen't have 2002005. so no result

    -----

    declare @bom table ([BOM Number] varchar(max),[Mat Number] varchar(max))

    insert...

  • RE: Parse XML Data to Table format

    Thank you Eirikur Eiriksson.

  • RE: Need to un-pivot some columns, pivot one column

    Please test the following .

    select

    [CampusID]

    ,[Campus]

    ,[TermID]

    ,[Term]

    ,[StudentID]

    ,[Qualification]

    ,[Programme]

    ,[status]

    ,[value]

    from

    (

    SELECT

    [CampusID]

    ,[Campus]

    ,[TermID]

    ,[Term]

    ,[StudentID]

    ,[Qualification]

    ,[Programme]

    ,[Repeat1stYear]

    ,[Repeat2ndYear]

    ,[Repeat3rdYear]

    ,[ProgTo2ndYear]

    ,[ProgTo3rdYear]

    ,[ProgToCompleteQual]

    ,[NotReturn2ndYr]

    ,[NotReturn3rdYr]

    ,[NotReturn4thYr]

    FROM [dbo].[MyTable]

    )p

    unpivot (value for [status]in

    (

    [Repeat1stYear]

    ,[Repeat2ndYear]

    ,[Repeat3rdYear]

    ,[ProgTo2ndYear]

    ,[ProgTo3rdYear]

    ,[ProgToCompleteQual]

    ,[NotReturn2ndYr]

    ,[NotReturn3rdYr]

    ,[NotReturn4thYr]

    ))as unpvt

    ORDER BY studentid, termid

    Regards

    J. Siva Kumar

  • RE: COMPARE TWO TABLES COPY MATCHING VALUS TO TABLE_C

    --method1:

    insert into table_c

    select a.* from table_a a join table_b b

    on a.id = b.id

    -- method2

    insert into table_c

    select a.* from table_a a

    where exists (select 1 from table_b b where...

  • RE: add serial number coloum and sno 1to 40000

    alter table table add slno bigint identity(1,1)

    regards

    J Siva Kumar

  • RE: SQL Function to remove excess characters

    SELECT 'SO-123456' AS OrderNo into #test

    UNION ALL

    SELECT 'SO-123456-01'

    UNION ALL

    SELECT 'SO-123456-2'

    UNION ALL

    SELECT 'SO-123457'

    UNION ALL

    SELECT 'SO-123457-1'

    UNION ALL

    SELECT 'SO-123457-02'

    UNION ALL

    SELECT 'SO-123458'

    union all

    select 'SO-123459=02'

    select * from #test where OrderNo like '%[^A-Z]-[0-9]%'

    DROP table #test

  • RE: "Running totals" query

    Hi, Please check the following code .

    declare @table table (id int identity(1,1),item varchar(10),amt int)

    insert into @table values (1,100),(2,200),(3,300),(4,400)

    declare @sumtotal int

    select @sumtotal = SUM(amt) from @table

    SELECT a.id, a.amt,@sumtotal-SUM(b.amt)

    FROM @table...

  • RE: Query to Exclude Duplicate values in different columns.

    Hi

    Yes, There is a flaw in the previous logic.:cool:

    Here is corrected version

    create table #nc (nc1 int,class int,nc2 int)

    insert into #nc

    values(110,1,112)

    ,(112,1,110)

    ,(210,2,212)

    ,(310,3,313)

    ...

  • RE: Query to Exclude Duplicate values in different columns.

    Hi

    This may help you.

    create table #nc (nc1 int,class int,nc2 int)

    insert into #nc

    values(110,1,112)

    ,(112,1,110)

    ,(210,2,212)

    ,(310,3,313)

    ,(313,3,310)

    ,(410,1,141)

    ,(329,7,231)

    select * from #nc

    select...

  • RE: Query Help- Cursor change into FOR WHILE LOOP, TEMP TABLE

    Hi

    I am sending sample procedure to avoid cursors. Implement this logic in your procedures. This may help you.

    declare @test_tab TABLE

    (

    [id1] [int] NULL,

    query [varchar](50) NULL,

    [result] [bit] NULL)

    insert into @test_tab values(1,'select...

  • RE: Evaluate expression and store the result

    Hi,

    Please check the following code. Little bit lengthy procedure.

    declare @tbl_expression TABLE

    (

    [id1] [int] NULL,

    [exp1] [varchar](50) NULL,

    [result] [bit] NULL)

    insert into @tbl_expression values(1,'30 > 50',Null)

    insert into @tbl_expression values(2,'70 > 50',Null)

    insert into @tbl_expression...

  • RE: Query help for a table

    Hi

    Check the following.

    declare @yourTable table (Id int identity(1,1),Transdate DATE);

    INSERT INTO @yourTable

    SELECT Transdate

    FROM (VALUES('2012-01-01'),('2012-01-07'),('2012-01-10'),('2012-01-12'),

    ('2012-01-18'),('2012-01-21'))a(Transdate);

    ...

  • RE: convert varchar to numeric

    Hi

    select convert(bigint,REPLACE ('10,00,000',',',''))

    Siva Kumar J

  • RE: Generating the (calender) date_dim in tsql with required columns

    Hi,

    You can try this one.

    declare @t table (id int identity(1,1),time_stamp date)

    declare @Daysin_Month table (Month_No int, No_of_Days int)

    declare @st date,@en date

    select @st = '2012-01-01'

    select @en = '2012-12-31'

    insert into @t

    select convert(varchar(10),GETDATE(),110)...

Viewing 15 posts - 1 through 15 (of 47 total)