OSQL : If table exists

  • Hello,

    I am in a situation where i need to BCP (out ) all the records from a table uisng a batch file.

    I was wondering how will i write the following logic

    if exists (SELECT name

    FROM sysobjects

    WHERE name = N'MY_TABLE_NAME'

    AND type = 'U')

    echo main..MY_TABLE_NAME >>..................

    .........................

    something something....................

    -----------

    bcp main..MY_TABLE_NAME out............................

  • Look up the SQLCMD logic in Books on line. Take a look at the switches. Or you can use bcp

    http://msdn.microsoft.com/en-us/library/ms162773.aspx

    BCP: http://msdn.microsoft.com/en-us/library/ms162802.aspx

    Also, please take this with a grain of salt, but a quick google search would have gotten this for you and as I have seen on here and it's noted in the forum policies to do a search before asking questions 🙂

    Chris

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply