Forum Replies Created

Viewing 15 posts - 61 through 75 (of 89 total)

  • RE: T-sql query to extract dependency results

    hi,

    the syntax error might be cause of table is not exists please create table which is commented,

    Logic: in first cte I find out the chain depends upon the col1.

    and...

  • RE: stored procedure with optional parameters

    CREATE PROC usp_procdetails

    @Param1 INT = 1

    @Param2 VARCHAR(100) = 'Default'--This can work by adding value also.

    AS

    BEGIN

    --Add your code depends upon default.

    END

    GO

    EXEC usp_procdetails

    GO

  • RE: Delete duplicate rows in a Table?

    DECLARE @tbl_Duplicate TABLE

    (

    ID INT

    )

    INSERT INTO @tbl_Duplicate VALUES(1),(2),(1),(3)

    --Before

    SELECT * FROM @tbl_Duplicate

    ;WITH CTE AS

    (

    SELECT

    ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ID) AS ROWID

    FROM

    @tbl_Duplicate

    )

    DELETE FROM CTE WHERE ROWID > 1

    --AFTER

    SELECT * FROM...

  • RE: How to create task in order to get one instead 3 column?

    DROP TABLE #t

    create table #t(customernumber varchar(10), notes varchar(10), lastvisitdate smalldatetime)

    insert into #t values(100000, 'text 1', '10.feb.2010')

    insert into #t values(100000, 'text 2', '10.feb.2010')

    insert into #t values(100000, 'text 3', '10.feb.2010')

    select customernumber+', '+CONVERT(VARCHAR(20),lastvisitdate,106)+'...

  • RE: Tsql conditional Join

    DECLARE @tblA TABLE

    (

    IDINT

    )

    DECLARE @tblB TABLE

    (

    IDINT

    )

    DECLARE @tblC TABLE

    (

    IDINT

    )

    INSERT INTO @tblA

    SELECT 1

    UNION ALL

    SELECT 2 UNION ALL

    SELECT 3 UNION ALL

    SELECT 4 UNION ALL

    SELECT 5

    INSERT INTO @tblB

    SELECT 1

    UNION ALL

    SELECT 2

    INSERT INTO @tblC

    SELECT 3...

  • RE: Turn rows into columns and calculate increment values

    IF ( OBJECT_ID( 'tempdb..#Databases' ) IS NOT NULL )

    DROP TABLE #Databases

    CREATE TABLE #Databases

    (

    ...

  • RE: read file names from folder

    DECLARE @tbl TABLE

    (

    File_Names VARCHAR(100)

    )

    INSERT INTO @tbl

    exec master.dbo.xp_cmdshell 'dir c:\*.xml /b'

    SELECT * FROM @tbl WHERE File_NamesLIKE'%xml%'

  • RE: Calculating Differences in Time Between Values in different columns and rows

    as per requirment first and Last Records Records with 0 days.

    SELECT Cd.*,DATEDIFF(dd,CD.End_Date,ISNULL(CE.Start_Date,CD.End_Date)) AS Day_DIFF FROM #Care_EpisodesCD

    LEFT JOIN

    #Care_EpisodesCE

    ON

    CD.PKID=CE.PKID-1AND

    CD.Person_ID=CE.Person_ID

  • RE: T-sql query to extract dependency results

    --create table abc(col1 varchar(20),col2 varchar(20))

    --

    --insert into abc values('5.N.1','5.N.4')

    --insert into abc values('5.N.4','5.N.5')

    --insert into abc values('5.N.5','5.N.6')

    --insert into abc values('5.N.6','5.N.9')

    --insert into abc values('5.N.1','5.N.10')

    --insert into abc values('5.N.2','5.N.4')

    --insert into abc values('5.N.10','5.N.11')

    --insert into abc...

  • RE: delete duplicates

    DECLARE @tbl TABLE

    (

    EMPIDINT,

    EmpNameVARCHAR(100)

    )

    INSERT INTO @tbl

    SELECT

    1, 'aaa'

    UNION ALL

    SELECT

    1, 'aaa'

    UNION ALL

    SELECT

    2, 'aaa'

    UNION ALL

    SELECT

    3, 'bbb'

    UNION ALL

    SELECT

    2, 'bbb'

    DELETE D FROM

    (

    SELECT

    ROW_NUMBER() OVER(PARTITION BY EMPID,EmpName ORDER BY EMPID) AS ROWS,

    EMPID,

    EmpName

    FROM

    @tbl

    )D

    WHERE

    ROWS> 1

    SELECT * FROM @tbl

  • RE: How to Get the First or Last X Rows without Group By

    DECLARE @table table

    (

    IDVARCHAR(100),

    DATETIME1DATETIME

    )

    INSERT INTO @table

    SELECT

    'AI1', 40001

    UNION ALL

    SELECT

    'AI1', 40002

    UNION ALL

    SELECT

    'AI1' ,40003

    UNION ALL

    SELECT

    'AI1' ,40004

    UNION ALL

    SELECT

    'AI1', 40005

    UNION ALL

    SELECT

    'AI1', 40006

    UNION ALL

    SELECT

    'AI2', 41001

    UNION ALL

    SELECT

    'AI2', 41002

    UNION ALL

    SELECT

    'AI2', 41003

    UNION ALL

    SELECT

    'AI2', 41004

    UNION ALL

    SELECT

    'AI2', 41005

    UNION ALL

    SELECT

    'AI2', 41006

    UNION ALL

    SELECT

    'AI3',...

  • RE: Insert Data Multiple Times

    DECLARE @Temp TABLE(version_id int,customer_id char(8),product_id char(20),month_id char(2),fiscal_year char(2),units numeric(18, 4),value numeric(18, 4))

    INSERT INTO @Temp

    SELECT

    1,'1','10','1','00',100,980.66

    UNION ALL

    SELECT

    15,'1','10','12','00',100,980.66

    UNION ALL

    SELECT

    14,'1','10','10','00',100,980.66

    UNION ALL

    SELECT

    13,'1','10','11','00',100,980.66

    UNION ALL

    SELECT

    1,'1','10','1','00',100,980.66

    UNION ALL

    SELECT

    2,'1','10','2','00',100,980.66

    UNION ALL

    SELECT

    3,'1','10','3','00',100,980.66

    UNION ALL

    SELECT

    4,'1','10','4','00',100,980.66

    UNION ALL

    SELECT

    5,'1','10','5','00',100,980.66

    UNION ALL

    SELECT

    6,'1','10','6','00',100,980.66

    UNION ALL

    SELECT

    7,'1','10','7','00',100,980.66

    UNION ALL

    SELECT

    8,'1','10','8','00',100,980.66

    UNION ALL

    SELECT

    9,'1','10','9','00',100,980.66

    UNION ALL

    SELECT

    10,'1','10','10','00',100,980.66

    UNION ALL

    SELECT

    11,'1','10','11','00',100,980.66

    UNION ALL

    SELECT

    12,'1','10','12','00',100,980.66

    SELECT

    [JAN],[FEB],[MAR],[APR],[MAY],[JUN],[JUL],[AUG],[SEP],[OCT],[NOV],[DEC]

    FROM

    (

    SELECT ...

  • RE: how to get only duplicate rows from table

    DECLARE @table TABLE

    (

    RowNum INT , Name VARCHAR(100), SomeValue VARCHAR(100)

    )

    INSERT INTO @table

    SELECT...

  • RE: I need this output(Please Help!!!)

    DECLARE @table table

    (

    IDVARCHAR(100),

    ZIPINT

    )

    INSERT INTO @table

    SELECT

    'AI1', 40001

    UNION ALL

    SELECT

    'AI1', 40002

    UNION ALL

    SELECT

    'AI1' ,40003

    UNION ALL

    SELECT

    'AI1' ,40004

    UNION ALL

    SELECT

    'AI1', 40005

    UNION ALL

    SELECT

    'AI1', 40006

    UNION ALL

    SELECT

    'AI2', 41001

    UNION ALL

    SELECT

    'AI2', 41002

    UNION ALL

    SELECT

    'AI2', 41003

    UNION ALL

    SELECT

    'AI2', 41004

    UNION ALL

    SELECT

    'AI2', 41005

    UNION ALL

    SELECT

    'AI2', 41006

    UNION ALL

    SELECT

    'AI3',...

  • RE: TRicky SQL

    DECLARE @agegrp TABLE

    (

    AGE INT

    )

    insert into @agegrp values (0);

    insert into @agegrp values (75);

    insert into @agegrp values (100);

    insert into @agegrp values (5);

    insert into @agegrp values (18);

    insert...

Viewing 15 posts - 61 through 75 (of 89 total)