Forum Replies Created

Viewing 15 posts - 121 through 135 (of 429 total)

  • RE: Trigger that creates a new trigger

    Will be possible with dynamic SQL. I really don't understand why would you want to do that.

    SET NOCOUNT ON

    GO

    CREATE TABLE Configuration

    (

    MyID INT

    )

    GO

    CREATE TABLE AnyTable

    (

    myID INT

    )

    GO

    CREATE TRIGGER [T1] ON [dbo].[Configuration]

    FOR...

  • RE: Retrieving the NT User Name from a query.

    If the access is through an application using ADO via application user. Then connection string property can be used to specify the NT User as the parameter in connection string...

  • RE: Using FROM @variable in SELECT statement...

    exec sp_MSforeachtable 'EXEC ( ''DECLARE @sql VARCHAR(1000) SELECT @sql = ''''?'''' + CHAR(9) + CONVERT(VARCHAR, COUNT(*)) FROM ? PRINT @sql'')'

  • RE: Using FROM @variable in SELECT statement...

    How about this

    exec sp_MSforeachtable 'EXEC ( ''SELECT TableName = ''''?'''', Rows = COUNT(*) FROM ?'')'

  • RE: Cumulative Count

    That is a good solution. Uses correlation instead of cross join.

  • RE: Cumulative Count

    I would assume when the orginal poster said he wouldn't want to use cursor that goes for loops as well.

  • RE: Cumulative Count

    SET NOCOUNT ON

    Declare @myTable TABLE

    (

    [Month] INT,

    Users INT

    )

    INSERT @myTable

    SELECT 1, 10 UNION

    SELECT 2, 20 UNION

    SELECT 3, 10 UNION

    SELECT 4, 5 UNION

    SELECT 5, 15 

    SELECT B.[Month],

     B.Users,

     SUM(CASE WHEN A.[Month] <= b.[Month] THEN A.Users ELSE 0 END) Cumulative

    FROM

     @myTable A

    CROSS...

  • RE: DATEDIFF Help

    SET NOCOUNT ON

    DECLARE @myTable TABLE

    (

    lname  VARCHAR(10),

    fname  VARCHAR(10),

    review_date DATETIME

    )

    INSERT @myTable

    SELECT 'lname1', 'fname1', DATEADD(DAY, -11, GETDATE())  UNION

    SELECT 'lname3', 'fname3', DATEADD(DAY, -10, GETDATE())  UNION

    SELECT 'lname4', 'fname4', DATEADD(DAY, -9, GETDATE())  UNION

    SELECT 'lname5', 'fname5', DATEADD(DAY, -8, GETDATE())  UNION

    SELECT 'lname6', 'fname6', DATEADD(DAY, -7,...

  • RE: order by returning data in wrong order

    I guess there is confusion in What is ASC and DESC.

    When there is no order by SQL Server would return the rows in ASC. When we specify DESC then it...

  • RE: SQL Insert

    HI Sergiy

    Can you give an example. I tried that without success.

  • RE: SQL Insert

    It is not possible to insert into two tables with one insert statement.

  • RE: help to summarise

    /*I would make a design something like this*/

    SET NOCOUNT ON

    /* Data Table */

    CREATE TABLE MyAcctsNew

    (

    Account VARCHAR(10),

    DateYear DATETIME,

    Amount NUMERIC(10,2)

    )

    INSERT MyAcctsNew

    SELECT 'A', '01/01/2000', 250.00 UNION

    SELECT 'A', '01/01/2001', 150.00 UNION

    SELECT 'A', '01/01/2002', 180.00...

  • RE: help to summarise

    SET NOCOUNT ON

    DECLARE @MyAccts TABLE

    (

    Account VARCHAR(10),

    Year1   NUMERIC(10,2) NULL,

    Year2   NUMERIC(10,2) NULL,

    Year3   NUMERIC(10,2) NULL

    )

    INSERT @MyAccts

    SELECT 'A1', 250.00, null, null UNION

    SELECT 'A1', null, 150.00, null UNION

    SELECT 'A1', null, null, 180.00

    SELECT SUM(COALESCE(Year1, 0)) Year1, SUM(COALESCE(Year2,...

  • RE: Join syntax to exclude rows

    SET NOCOUNT ON

    DECLARE @TransData TABLE

    (

    GLAcct    VARCHAR(25),

    AcctDetls VARCHAR(10)

    )

    INSERT @TransData

    SELECT '1', 'AcctDetls1' UNION

    SELECT '2', 'AcctDetls2' UNION

    SELECT '3', 'AcctDetls3' UNION

    SELECT '4', 'AcctDetls4' UNION

    SELECT '5', 'AcctDetls5' UNION

    SELECT '6', 'AcctDetls6' UNION

    SELECT '7', 'AcctDetls7'

    DECLARE @ExcludedGLAccounts...

  • RE: Transform columns into rows

    SET NOCOUNT ON

    DECLARE @OldTable TABLE

    (

    StoreID  INT,

    WeekA  NUMERIC(10,2),

    WeekB  NUMERIC(10,2),

    WeekC  NUMERIC(10,2),

    WeekD  NUMERIC(10,2),

    WeekE  NUMERIC(10,2)

    )

    INSERT INTO @OldTable

    SELECT 1, 23.4, 43.5, 23.6, 45.6, 56.7 UNION

    SELECT 2, 24.4, 73.5, 73.6, 45.7, 16.7 UNION

    SELECT 3, 25.4, 63.5, 27.6, 43.6, 46.7

    DECLARE @NewTable TABLE

    (

    StroreID INT,

    WeekID  VARCHAR(10), -- Iwould keep...

Viewing 15 posts - 121 through 135 (of 429 total)