Forum Replies Created

Viewing 15 posts - 2,161 through 2,175 (of 2,462 total)

  • RE: Do I need to use cursors for this?

    First, welcome to SSC!

    If I understand your question correctly you have some VB code that accepts parameters, builds a query based on those parameters then sends that query (ad...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Replication DB migration on new sql server 2008R2

    We will be planning to migrate sql 2005 and sql 2008R2 on new windows 2008R2 server, we have one Replicated DB which ones we are subscribing and we don't have...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Case statements advice - query case field?

    Instead of the case statement you can also do this:

    SELECT ISNULL(thing1.name,(ISNULL(thing2.name,thing3.name))) AS name

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Replication pre-requisties

    First, check out the Stairway to SQL Server Replication[/url] by Sebastian Meine.

    I am going to set up replication in an OTLP environment. I would like to know what as...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Query Help - To delete old files

    GregoryF (8/8/2013)


    I use forfiles (google it for the reference on how to use) call from xp_cmdshell. It alows be to delete files older than n days, and you can...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Query Help - To delete old files

    Sreejith! (8/8/2013)


    Hi All,

    Looking for assistance to develop T-SQL code

    Requirement is to delete old files from directory & its sub-directories(say F:\Temp\test\), which were placed in directory before 1 week...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Pivot columns

    ksrikanth77 (8/8/2013)


    The Data I have in my Category code column in my source table is as below, as an example I just posted it as A B C D.

    My...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Pivot columns

    Below is a script that:

    1) Creates the sample data

    2) Queries the sample data for the desired results

    -- (1) Let's build the table structure

    DECLARE @source_table TABLE (ID int primary key,...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: SELECT ... INTO NewTable without nulls

    You could do something like this:

    USE tempdb;

    DECLARE @source_table varchar(100)='sys.all_columns',--Source Table

    @dest_table varchar(100)='new_table',--destination table (created by SELECT INTO)

    @column varchar(100)='is_column_set',--column to swich to NOT NULL

    @sql_prep varchar(1000),

    @insert_sql varchar(1000),

    @alter_sql varchar(1000),

    @data_type varchar(100);

    SET @sql_prep='IF OBJECT_ID('''+DB_NAME()+'..'+@dest_table+''')'+' IS...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: sp_spaceused columns?

    I created a stored procedure you can use.

    Sample data:

    use tempdb;

    IF OBJECT_ID('tempdb.dbo.demo') IS NOT NULL DROP TABLE dbo.demo;

    CREATE TABLE dbo.demo (col1 varchar(1000), col2 varchar(1000));

    WITH tally(n) AS (SELECT ROW_NUMBER() OVER (ORDER...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Starting point of a Join

    sharonsql2013 (8/2/2013)


    What do you mean by a staring point of a Join?

    I am creating a join with some tables and I have been asked table A to be starting point...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Need help with T-SQL to combine email addresses

    Sean Lange (8/2/2013)


    heh I forgot the semicolon in my post. Alan you don't need to do this with a subselect, just a simple query works.

    SELECT cEmail + ';'

    FROM #people

    FOR XML...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Need help with T-SQL to combine email addresses

    You don't need a loop to do what you were trying to do. This would do the trick

    DECLARE @emails varchar(5000)=''

    SELECT @emails=@emails+';'+cEmail

    FROM dbo.people;

    This technique, however, can give you data issues... The...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Easy (I hope) join question

    This is what I came up with

    --SAMPLE DATA

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

    DROP TABLE #table_A;

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

    DROP TABLE #table_B;

    CREATE TABLE #table_A (name varchar(20), [address] varchar(20));

    CREATE TABLE #table_B (name varchar(20),...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: String Manipulation

    I put together a little sample code and a few examples (note my comments) for a couple common scenarios

    DECLARE @x TABLE (val varchar(20));

    INSERT @x VALUES ('two words'),('two words '),('oneword'),(' leading...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 15 posts - 2,161 through 2,175 (of 2,462 total)