Forum Replies Created

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

  • RE: Looking For Duplication

    ;WITH CTEs

    AS (

    SELECTO.ProductID,

    O.OrderDate,

    O.ProductClass,

    O.ProductType,

    DENSE_RANK() OVER (PARTITION BY O.ProductID,O.OrderDate,O.ProductClass,O.ProductType ORDER BY NEWID()) 'Duplicate'

    FROMtmpEvalRecs R(NOLOCK) JOIN tmpOrders O(NOLOCK)

    ON(R.recordid = O.recordid)

    )

    SELECT * FROM CTEs WHERE Duplicate > 1

    Note:

    = 1 (Single Occurance)

    >1 (Multiple...

  • RE: Adding mutiple column in existing Table

    SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='TABLENAME'

    SELECT [NAME] FROM SYS.SYSCOLUMNS WHERE ID = OBJECT_ID('TABLENAME')

    SELECT [NAME] FROM SYS.COLUMNS WHERE [OBJECT_ID] = OBJECT_ID('TABLENAME')

    SP_COLUMNS 'TABLENAME'

  • RE: Can't get sp_create_plan_guide to work

    According to MS BOL , OPTION Caluse will have QueryHint

    query_hint ::=

    { { HASH | ORDER } GROUP

    | { CONCAT | HASH | MERGE } UNION

    ...

  • RE: query to delete 'almost' duplicate rows

    DELETE MyTable FROM (SELECT IdentityColumn,DENSE_RANK() OVER(PARTITION BY ObjectId,DataKey ORDER BY NEWID()) 'Rank' FROM MyTable) MyTable1

    WHERE MyTable.IdentityColumn =MyTable1.IdentityColumn

    AND MyTable1.Rank > 1

  • RE: How to insert/copy rows from one table to another?

    SELECT 1 'Col1',col 'Col2' INTO tbDestination FROM tbSource

  • RE: Max 3

    Finding Nth Position without TOP :

    ;WITH Salary

    AS (SELECT Emp_ID,Emp_Name,Salary,DENSE_RANK() OVER(ORDER BY Salary DESC ) 'Rank' FROM MyTable)

    -- Finding Max 3 Salaries

    SELECT * FROM Salary WHERE Rank <=3

  • RE: Getting XML in a table format

    Can U post your XML data ?

  • RE: Obtaining the name of machine you are running a SQL statement from

    -- It will produce ServerName/Instance Name

    SELECT HOST_NAME() 'Client Name',SERVERPROPERTY('SERVERNAME') 'DB Server Name'

    --OR

    -- It will produce ServerName

    SELECT HOST_NAME() 'Client Name',SERVERPROPERTY('MACHINENAME') 'DB Server Name'

  • RE: Getting XML in a table format

    It might be Node level mismatch. change the value 1 to 2 and try...

    [font="Verdana"]SELECT * FROM OPENXML (@idoc, '/ROOT/EVENT_INSTANCE',2)[/font]

  • RE: HELP needed with Syntax error ALTER INDEX

    According to MSDN specification....

    ALTER INDEX cannot be used to repartition an index or move it to a different filegroup. This statement cannot be used to modify the index definition, such...

  • RE: I have uniqueIdentifiers as foreign keys

    [font="Verdana"]Insert Into dbo.Apartment(apartmentID, apartmentDescID, apartmentNumber, apartmentFloorLevel, apartmentVacant)

    Values(Default, ?, '22A', '2', 'Yes')

    Insert Into dbo.Apartment(apartmentID, apartmentDescID, apartmentNumber, apartmentFloorLevel, apartmentVacant)

    Values(Default, ?, '7', '1', 'Yes')

    Insert Into dbo.Apartment(apartmentID, apartmentDescID, apartmentNumber, apartmentFloorLevel, apartmentVacant)

    Values(Default, ?, '20', '2',...

  • RE: how to convert csv values to a table?

    [font="Verdana"]DECLARE @TABLE1TABLE (IDINT)

    INSERT @TABLE1 VALUES(1)

    INSERT @TABLE1 VALUES(2)

    INSERT @TABLE1 VALUES(3)

    INSERT @TABLE1 VALUES(4)

    INSERT @TABLE1 VALUES(5)

    DECLARE @IDsVARCHAR(MAX)

    SELECT @IDs = COALESCE(@IDs,'') + CAST(ID AS VARCHAR) + ',' FROM @TABLE1

    SELECT LEFT(@IDs,LEN(@IDs)-1) 'Result'

    (OR)

    ;WITH CTEs(Result) AS (SELECT...

  • RE: how to convert csv values to a table?

    [font="Courier New"]DECLARE @s-2 VARCHAR(500)

    DECLARE @X XML

    SELECT @s-2='1,2,3,4,5'

    SELECT @X = '&LT;Data&GT;' + REPLACE(@S,',','&LT;/Data&GT;&LT;Data&GT;') + '&LT;/Data&GT;'

    SELECT N.value('.','varchar(max)') 'Result' from @X.nodes('Data') as T(N)[/font]

  • RE: Selecting 2nd or 3rd Duplicate in a recordset

    It'll show SECOND & THIRD

    ;WITH CTEs

    AS (SELECT Bldg,Job,DENSE_RANK() OVER(PARTITION BY Job ORDER BY NEWID()) 'Repeats' FROM #BuildingJob)

    SELECT * FROM CTEs WHERE Repeats IN(2,3)

  • RE: Please help to use BCP

    Try this....

    Microsoft SQL Server 2005 --> Configuration Tools -->

    SQL Server Configuration Manager -->

    SQL Server 2005 Network Configuration --> Enable TCP-IP

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