Forum Replies Created

Viewing 15 posts - 46 through 60 (of 81 total)

  • RE: Need Help with Query

    Looking for this query.

    SELECT DISTINCT Owner,PropertyId FROM #Table

  • RE: Top N and group by query...

    Try this out

    DECLARE @Rows INT

    SELECT  @Rows = 200

    -- Replace @tbl with your actual tablename

     

    SELECT A.*

    FROM @tbl AS A

     LEFT JOIN  (

       SELECT  ProjId,

        MIN(EmailId) AS MinId,

        MAX(EmailId) AS MaxId,

        COUNT(ProjId) AS RCnt

       FROM @tbl

       GROUP BY ProjId

      &nbsp

  • RE: Manipulating Dates using SQL

    Hi

    SELECT  REPLACE(CONVERT(VARCHAR(10),GETDATE(),120),'-','')

    Ram

  • RE: Query Analyzer Extended

    May be just give a try.

    USE NorthWind

    GO

    DECLARE @tblName VARCHAR(35)

    SELECT @tblName = 'Products'

    SELECT  [DeclareStmt] = RTRIM('DECLARE @'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)

            +CASE   WHEN T.[Name] IN        ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',

                                            'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')

                            THEN    UPPER(T.[Name])

                    WHEN T.[Name] IN ('DECIMAL','NUMERIC')

                            THEN    UPPER(T.[Name]) + + '('...

  • RE: Query Analyzer Extended

    May be just give a try.

    USE NorthWind

    GO

    DECLARE @tblName VARCHAR(35)

    SELECT @tblName = 'Products'

    SELECT  [DeclareStmt] = RTRIM('DECLARE @'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)

            +CASE   WHEN T.[Name] IN        ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',

                                            'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')

                            THEN    UPPER(T.[Name])

                    WHEN T.[Name] IN ('DECIMAL','NUMERIC')

                            THEN    UPPER(T.[Name]) + + '('...

  • RE: Creating Dynamic Tables

    Try this.

    declare @tablename varchar (100)

    set @tablename = '#BackupFile_' + replace(replace(cast(getdate() as varchar),' ',''),':','')

    select @tablename

    EXEC ('CREATE TABLE '+@tablename+ '([name] [nvarchar] (100))')

     

    Ram

     

     

  • RE: Create a table from an EXEC statement - Driving me mad!!

    Thanks Sergiy! Good catch

    Ram

  • RE: Create a table from an EXEC statement - Driving me mad!!

    INSERT INTO table variable from EXEC not allowed. It can be done on Temptables.

    Try this out

     

    DECLARE @InstanceDB as varchar(100)

    CREATE TABLE #InstanceTable (Code varchar(100),FinancialYear varchar(100),ServiceID int)

    ---DECLARE @InstanceTable TABLE (Code varchar(100),FinancialYear varchar(100),ServiceID...

  • RE: update table question

    Thanks Prazad!!!

     

  • RE: Derived Column Using Previous Value!

    You may try like this...

    DECLARE @VAL VARCHAR(10)

    SELECT @VAL =''

    SELECT @VAL =NULL

    SELECT CASE WHEN (LEN(LTRIM(RTRIM(@VAL))) = 0 OR @val IS NULL) THEN '1999-01-01' ELSE @val END

     

     

  • RE: update table question

    Try this!

    BEGIN

     SET NOCOUNT ON

     

     DECLARE @vuser VARCHAR(20)

     

     DECLARE @tbl TABLE

      ([Id] VARCHAR(20),

      WCode INT,

      Reason VARCHAR(10),

      HCode VARCHAR(10),

      Loc VARCHAR(10))

     

     SELECT @vuser = ''

     INSERT INTO @tbl VALUES ('user1',125,'rsn1','cd1','loc1')

     INSERT INTO @tbl VALUES (NULL,128,'rsn3','cd27','loc3')

     INSERT INTO @tbl...

  • RE: update table question

    Try this out

    BEGIN

     SET NOCOUNT ON

     DECLARE @vuser VARCHAR(20)

     DECLARE @tbl TABLE

      ([Id] VARCHAR(20),

      WCode INT,

      Reason VARCHAR(10),

      HCode VARCHAR(10),

      Loc VARCHAR(10))

     SELECT @vUser = ''

     INSERT INTO @tbl VALUES ('user1',125,'rsn1','cd1','loc1')

     INSERT INTO @tbl VALUES (NULL,128,'rsn3','cd27','loc3')

     INSERT INTO @tbl VALUES (NULL,721,'rsn3','cd4','loc5')

     INSERT INTO @tbl VALUES ('user2',122,'rsn3','cd1','loc3')

     INSERT INTO @tbl VALUES...

  • RE: Query Help

    It does not work that way!!

    [Microsoft Excel]  = COUNT(CASE WHEN SoftWare = 'Microsoft Excel' THEN SoftWare ELSE NULL END),

    This one might work for you

    SET NOCOUNT ON

    DECLARE @tbl...

  • RE: Query Help

    You may try like this too..

    SELECT [User] AS UserName

     [MicrosoftExce]  = CASE WHEN Max(SoftWare) = 'Microsoft Excel' THEN COUNT(Max(SoftWare)) ELSE 0 END,

     [MicrosoftAccess]  = CASE WHEN Max(SoftWare) = 'Microsoft Accessl' THEN COUNT(Max(SoftWare)) ELSE...

  • RE: INSERT Question (best way to do this)

    INSERT  INTO TableOne (AcctNo)

    SELECT AcctNo

    FROM  TableTwo AS B

    WHERE  NOT EXISTS (SELECT 1 FROM TableOne AS A WHERE A.AcctNo = B.AcctNo)

     

Viewing 15 posts - 46 through 60 (of 81 total)