Forum Replies Created

Viewing 15 posts - 616 through 630 (of 1,347 total)

  • RE: Update only if not null

    >I guess not.

    Guess again

    UPDATE products

     SET productdetail = @detail, 

     --Set productprice equal to itself, if @price is null

     productprice = IsNull(@price, productprice)

    WHERE productid = @id

    [Edit]...

  • RE: UPDATE Query taking hours to run in DTS Package???

    Lookups can be useful if you need to look something up on a different data source.

    With 2 tables in the same data source, a lookup will nearly always be slower. You can...

  • RE: how to copy data from another sql server instance

    Create a linked server. Read BOL topic sp_addlinkedserver

    Once the link is created, T-SQL is as follows:

    INSERT INTO YourTable  (Column List)

    SELECT Column List

    FROM [LinkName].[DatabaseName].[DBOwner].[TableName]

     

  • RE: Create Index on Network drive

    >>If I create the index on the array, it provides no real improvement because SQL reads from the same drive that the db is on

    That part is definitely not true.

    An...

  • RE: Help with Left Join in query and ordering

    If you have a table that is left-joined, and you then apply a WHERE to that table, you force it back to an INNER JOIN. Try this:

    SELECT PRODUCTS.PRODUCT_ID, PRODUCTS.P_NAME, VOTES.V_SCORE

    FROM...

  • RE: How to find missing entries

    For a set-based solution, you need a table of all possible numbers. You can get this by cross-joining 2 tables of known large size:

    -- Limit to as many...

  • RE: problem using sum / round with group

    You'll need to post the full SQL, including the GROUP BY.

     

  • RE: nvarchar field problem

    By changing the column list in SELECT, you potentially change the order in which rows are returned.

    It may be you are just seeing a different part of the resultset.

    Only way...

  • RE: Extremely slow queries when doing an OR join.

    If this is taking 30+ minutes on only 50K rows, then there's more going on, and most likely cardinality issues.

    What is the uniqueness of field1 and field2 in the 2...

  • RE: problem using sum / round with group

    1 rounds before summing, the other sums before rounding.

    If you remove decimal places before summing, and the numbers are all positive, then obviously you'll get a different number .

    Sum(5.4 +...

  • RE: UPDATE Query taking hours to run in DTS Package???

    1. Since there is no clustered index, the table may be a highly fragmented heap, requiring more disk I/O than necessary

    2. If the database is running in full recovery mode,...

  • RE: Invalid column error

    IF @@ROWCOUNT = 0

    BEGIN

        ALTER TABLE [dbo].[RESULTS] ADD [TOTAL_VOTES] int not NULL DEFAULT (0);

        UPDATE RESULTS SET TOTAL_VOTES = (OPTION1 + OPTION2 + OPTION3 + OPTION4 + OPTION5 +...

  • RE: Invalid column error

    >>How do you do Dynamic SQL for the update statement?  I've never done dynamic SQL...

    Declare @sql varchar(1000)

    if (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS

     WHERE TABLE_NAME = 'RESULTS'

     AND COLUMN_NAME = 'TOTAL_VOTES'

       ) = 0

    begin

     ...

  • RE: Error importing a simple txt file into SQL

    If you have a mix of qualified and non-qualified text fields, you are probably going to have to do some sort of data scrubbing either before or after import.

    You could...

  • RE: @@Identity - Multiple inserts, multiple tables

    The SQL for the "link table" (intersection table) would look something like this:

    INSERT INTO Purchase_Inv_Trans

      (Inv_ID, Transaction_ID)

    SELECT

      pi.InvoiceID, t.TransactionID

    FROM [Purchase Invoices] As src

    INNER JOIN Purchase_Invoice As pi

      On...

Viewing 15 posts - 616 through 630 (of 1,347 total)