Forum Replies Created

Viewing 15 posts - 781 through 795 (of 897 total)

  • RE: Removing identity property

    I think it should be

    Select IDENTITY(Numeric, @MAX_ID, 1) AS RowNum, * into #t2 from #t1

  • RE: find foreign key colum using the primary key value

    This does work in my machine. Check the alias name given to COUNT(*) field.

    DECLARE @strColumnName VARCHAR(100)

    DECLARE @strTableName VARCHAR(100)

    DECLARE @strColumnValue VARCHAR(100)

    DECLARE @strSQL ...

  • RE: find foreign key colum using the primary key value

    Add this block above the EXECUTE( @strSQL ) statement

    SET@strSQL = ' SELECT * '

    + ' FROM ( ' + @strSQL + ' ) T '

    + ' WHERE Count > 0...

  • RE: find foreign key colum using the primary key value

    This should help..

    DECLARE@strColumnNameVARCHAR(100)

    DECLARE@strTableNameVARCHAR(100)

    DECLARE@strColumnValueVARCHAR(100)

    DECLARE@strSQLVARCHAR(MAX)

    SET@strColumnName = 'EmployeeID'

    SET@strTableName = 'mstEmployees'

    SET@strColumnValue= 6

    SELECT@strSQL = COALESCE( @strSQL + ' UNION ALL ' + CHAR(10), '' )

    + ' SELECT''' + OBJECT_NAME( FK.fkeyid ) + ''' TableName, COUNT(*)...

  • RE: Delete duplicate rows in a Table?

    Trouble Shooter (4/12/2010)


    Hi,

    Can u delete two duplicate row using row_number function

    if yes ,please let me know

    Yes, it does. It can delete any number of rows.

    Try this

    DECLARE@tblTable TABLE

    (

    Col1 INT

    )

    INSERT@tblTable

    SELECT1 UNION ALL

    SELECT1...

  • RE: Delete duplicate rows in a Table?

    Trouble Shooter (4/12/2010)


    Hi,

    2 is the variable only.

    u can set any value there like 1 ,3 etc as per your requirement.

    But, don't you think the method would be a bit tedious....

  • RE: Delete duplicate rows in a Table?

    Trouble Shooter (4/12/2010)


    Hi ,

    Did u try it Mr. SSCertifiable ?

    Look at this buddy

    rajagopalanseeth (3/29/2010)


    if there is 3 duplicate records found, i want to delete only 2 records and keep the...

  • RE: how to write query for getting Top3 rows from each userId

    You can use the ROW_NUMBER() function. It would have been helpful if you would have given us the table structure and some sample data to work with.

  • RE: Select with Sub Select to show results in columbs

    Glad to help you out:-)

  • RE: Select with Sub Select to show results in columbs

    This should help you out..

    DECLARE @tblTable TABLE

    (

    AN_CODE1 VARCHAR(50),

    AN_CODE2 VARCHAR(50),

    [VALUE] INT

    )

    INSERT @tblTable

    SELECT 'CAP', 'ENERGY1', 200 UNION ALL

    SELECT 'CUR', 'ENERGY1', 400

    SELECTAN_CODE2,

    SUM( CASE WHEN AN_CODE1 = 'CAP' THEN [VALUE] ELSE 0 END )...

  • RE: How to execute Index?

    chandrasekaran.ganapathy (4/8/2010)


    Hi Kingston and all,

    Got it. I have read some article. So If i make a query like

    Select * from employeeId where employeeId between 'xxxxxx' and 'xxxx'

    or

    Select * from...

  • RE: Return groups in random order

    My method makes use of ROW_NUMBER() and NEWID(), ROW_NUMBER() a ranking function and NEWID() a function that returns a unique value for every row in the result. You can Google...

  • RE: How to execute Index?

    You can never execute an Index. To get the data you will have to always SELECT * from the table.

    And one more thing, is you get some script from somewhere...

  • RE: Return groups in random order

    Looks like too much of code to me too. But this works

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

    DROP TABLE #tmpOrdered

    DECLARE@tblTable TABLE

    (

    FranchiseID INT,

    SectorID INT

    )

    INSERT@tblTable

    SELECT 1,...

  • RE: Data Insert

    Trybbe (4/8/2010)


    Msg 544, Level 16, State 1, Line 2

    Cannot insert explicit value for identity column in table 'Clusters' when IDENTITY_INSERT is set to OFF.

    the query I tried is:

    Insert into Areas

    Select...

Viewing 15 posts - 781 through 795 (of 897 total)