Forum Replies Created

Viewing 12 posts - 16 through 28 (of 28 total)

  • RE: Selecting specific row in a join

    SELECT B.REF,B.INFO,MAX(A.ACTION_DATE) 'ACTION_DATE'

    FROM #tableB AS b WITH(NOLOCK)

    LEFT JOIN #tableA AS a WITH(NOLOCK)

    ON (b.ref = a.ref)

    GROUP BY B.REF,B.INFO

  • RE: Query results to a text file in a specified path

    Creating Output file at DB Server :

    Goto Query Analyzer and Do the following

    XP_CMDShell 'SQLCMD -S ServerName/IP -d DataBaseName

    -U UserID -P Password -Q "SELECT Statement" -o OutputFilePath'

    XP_CMDShell 'TYPE FilePath'

    Creating Output...

  • RE: regarding the identity

    The IDENTITY column must be of data type int, bigint, smallint, tinyint,decimal or numeric with a scale of 0.

  • RE: Chinese chars issue in T-SQL

    It will work

    DECLARE @result NVARCHAR(MAX)

    SELECT @result = N'???????'

    PRINT @result

    (Or)

    DECLARE @result NVARCHAR(MAX)

    SELECT @result = N'???????'

    PRINT @result COLLATE Chinese_PRC_CI_AI

  • RE: diplay first word before a space

    Try this....

    SELECT [Text],LEFT([Text],CASE WHEN CHARINDEX(' ',[Text])-1 >0 THEN CHARINDEX(' ',[Text])-1 ELSE LEN([Text]) END) FROM TABLENAME

  • RE: Optimized and fast query for simple join?

    Select T1.Date,t1.SName,SUM(t2.Price) 'Price' from Table1 t1(NOLOCK) JOIN Table2 t2(NOLOCK)

    ON(t1.SID = t2.ID)

    GROUP BY T1.Date,t1.SName

  • RE: How to write Conditional Where Clause

    [font="Verdana"]Hi

    SELECT [NAME] FROM TABLEINFO(NOLOCK)

    WHEREX = CASE WHEN @X 0 AND @X IS NOT NULL THEN @X ELSE X END

    ANDY = CASE WHEN @Y 0 AND @Y IS NOT NULL THEN...

  • RE: Conditional Index Rebuild

    Hi

    Pls look into the BOLD area which was newly added. Now your script will generate and execute the ALTER scripts...

    USE MyDatabase

    DECLARE @TableName NVARCHAR(128)

    DECLARE @IndexName NVARCHAR(128)

    DECLARE @cmd NVARCHAR(500)

    DECLARE @DB_IDINT

    SELECT @DB_ID =...

  • RE: SQL Server profiler -> column filter "Error"

    1. Select the Event 'User Error Message' Under 'Errors & Warnings' Event Group. It will show you the actual Constraints' Error messages

    2. Filter the column TextData as %Message You want...

  • RE: duplicate records

    Create Table #Data

    (

    FirstNameVARCHAR(50),

    EMailVARCHAR(50)

    )

    GO

    Insert #Data Values('AAAAA','AAAAA@a.com')

    Insert #Data Values('BBBBB','BBBBB@a.com')

    Insert #Data Values('AAAAA','AAAAA@a.com')

    Insert #Data Values('CCCCC','CCCCC@a.com')

    Insert #Data Values('AAAAA','AAAAA@a.com')

    Insert #Data Values('CCCCC','CCCCC@a.com')

    GO

    Select FirstName,EMail From #Data

    GO

    SELECT FirstName,EMail,

    CASE WHEN DENSE_RANK() OVER(PARTITION BY EMail ORDER BY NEWID()) >1 THEN 'Duplicate'...

  • RE: Finding Tables Used on 1000 SP

    Hi

    Just Run the script....

    DECLARE @PROCEDUREVARCHAR(40)

    DECLARE @TABLESVARCHAR(MAX)

    DECLARE @IterateINT

    SELECT @Iterate = 1

    SELECT

    DENSE_RANK() OVER (ORDER BY S.ID) 'GROUPID',

    OBJECT_NAME(S.ID) 'SP',

    OBJECT_NAME(S.DEPID)'TableS' INTO #GROUPS

    FROMSYS.SYSDEPENDS S(NOLOCK) JOIN SYS.SYSOBJECTS SS

    ON(S.DEPID = SS.ID)

    WHERESS.[TYPE]='U'

    GROUP BY S.ID,OBJECT_NAME(S.DEPID),OBJECT_NAME(S.ID)

    WHILE @Iterate <= (SELECT MAX(GROUPID)...

  • RE: Query Performance issue

    Hi

    Can u pls ensure the following activities...

    1. Check the TIME of the Job executed.

    2. In that SAME TIME, Is there any other activities performing on the Database (ie: Backup /...

Viewing 12 posts - 16 through 28 (of 28 total)