Help needed regarding SQL Server.

  • Hi All,

    Actually i have number of questions listed below.

    1. I just want to know that how do i save output of the queries to a text file through T-SQL,

    2. How can i check whether SQL Server Services are running (MSDTC, SQL Server Agent, SQL Server etc.) using T-SQL.

    3. Can i create Index on a first 5 characters of a varchar field.

    4. I have some views built on Oracle Linked Server and that contains nested queries and some time those queries return more than one rows which forces my DataSyncronization routine to crash. I want to trap these kind of errors, is it possible to do this?

    Your early reply will be highly appreciated.

    Thanks in Advance

    Kind Regards,

    Affan

  • For pure TSQL (is there such a thing?) you can use sp_oacreate to use the file system object or a recordset object to write to disk. DTS offers the same abilities with less headache. If you're running the query from a client you can redirect the output to a file (see OSQL in BOL).

    Andy

    http://qa.sqlservercentral.com/columnists/awarren/

  • 1) Thru T-SQL you don't have an option. You can however use OSQL or ISQL with the output commands to send data to a text file, save the results in QA to a tet file, or use DTS or BCP to query and output to a text file.

    2) Sorry but if you got connected then you can rule the need to check if SQL Server Service is running. As for the others I have not seen anything built in to do this. However, if something you really need I am sure an Extended Stored Procedure either exists or can be built to do just that.

    3) No you cannot index a column partially. If you need to do this then the best you can do is create another column and store the first 5 characters, but then you need to make sure the data is kept consistant and will need to add INSERT and UPDATE triggers to control this on changing.

    4) Sorry I haven't tried this so not sure how, I am pretty sure you can. Can you walk us thru what you are doing and where?

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Thaks all for prompt help

    Actually, we have linked our SQL Server with ERP system in Oracle. We sync the orders data from oracle to SQL Server for Manipulation. so we are using our custome T-SQL routines to import, validate and clean the data. so for this matter we have made views on ORACLE server using Linked Server. So i want to trap errors returned by ORACLE views like subqueries returning more than 1 rows, since ERP system is unnormalized.

    Is there any way to trap these sort of errors?

    Kind Regards,

    Affan

  • Regarding point 3. Would creating a view with a clustered index on left(<colname>,5) achieve this?

Viewing 5 posts - 1 through 4 (of 4 total)

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