Hi, all. I'm fairly new to SQL, and I have been trying to create a table
from a text file. I have been looking at this for days, and can't find the
problem. I get a syntax error " Line 55: Incorrect syntax near
'DateUpdated'." Here is the query. Any suggestions would be appreciated,
as I am trying to learn and improve.
Use ACH
go
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ImportFiles]') and OBJECTPROPERTY(id, N'IsProcedure') =
1)
drop procedure [dbo].[ImportFiles]
GO
-- remove filename just imported
delete #Dir where datarow = @FileName
exec @MergeProc
END
drop table ##Import
drop table #Dir
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[MergeData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[MergeData]
GO
SELECT Substring(DataRow,1,9) AS RoutingNum,
Substring(DataRow,10,1) AS OfficeCode,
Substring(DataRow,11,9) AS ServicingFRBNum,
Substring(DataRow,20,1) AS RecordType,
convert(datetime,Substring(DataRow,21,6)) AS ChangeDate,
Substring(DataRow,27,9) AS NewRoutingNum,
Substring(DataRow,36,36) AS BankName,
Substring(DataRow,72,36) AS BankAddress,
Substring(DataRow,108,20) AS City,
Substring(DataRow,128,2) AS State,
Substring(DataRow,130,5) + '-' + Substring(DataRow,135,4) AS Zipcode,
Substring(DataRow,139,3) + '-' + Substring(DataRow,142,3) + '-' +
Substring(DataRow,145,4) AS Phone,
Substring(DataRow,149,1) AS StatusCode,
Substring(DataRow,150,1) AS DataView,
Substring(DataRow,151,5) AS Filler
DateUpdated datetime AS DateUpdated
FROM ##Import
GO
I have a text file which needs to be created into a table (let's call it DataFile table). For now I'm just doing the manual DTS to import the txt into SQL server to create the table, which works. But here's my problem....
I need to extract data from DataFile table, here's my query:
select * from dbo.DataFile where DF_SC_Case_Nbr not like '0000%';
Then I need to create a new table for the extracted data, let's call it ExtractedDataFile. But I don't know how to create a new table and insert the data I selected above into the new one.
Also, can the extraction and the creation of new table be done in just one stored procedure? or is there any other way of doing all this (including the importation of the text file)?
Hey guys, I have a dilemma and hope someone can help.
I don't know of any utilities or commands in SQL that do this but I hope someone does.
What I need to do is something like a bcp import a text file in. I can do that with DTS as well. But what I wanted to do is create a table on the import. So lets say, I am importing a tab-delimited file with column names as the first row that is called ax.txt. On import, it would create the table ax with the column names in the file and then import the data into that table.
I hope I explained it clearly. Please let me know if there is anything I can use to do this without writing lots of code.
I have an idea how to do it the long way but hope there is a utility that already does it.
I am trying to run an SELECT statement with a CONTAINS statement from a aspx.net solution built using Visual Web Developer 2005 express edition. When I try to run the thing it throws an error saying
"Cannot use a CONTAINS or FREETEXT predicate on table or indexed view 'JournalArticle' because it is not full-text indexed.".
I don't have access to the SQL Express server, I interface through Server Management Studio Express. There is an option to create a full-text index from the menu, but it is greyed out, presumably because there is no full-text catalogue. This is my real question, How do I create a full-text catalogue using Server Management Studio Express? The help function only provides examples of sql code, which I assume must be performed using sql server (which I don't have access to). Any help would be greatly appreciated.
Hi, I want to create a text file and write to text it by calling its assembly from Stored Procedure. Full Detail is given below
I write a code in class to create a text file and write text in it. 1) I creat a class in Visual Basic.Net 2005, whose code is given below: Imports System Imports System.IO Imports Microsoft.VisualBasic Imports System.Diagnostics Public Class WLog Public Shared Sub LogToTextFile(ByVal LogName As String, ByVal newMessage As String) Dim w As StreamWriter = File.AppendText(LogName) LogIt(newMessage, w) w.Close() End Sub Public Shared Sub LogIt(ByVal logMessage As String, ByVal wr As StreamWriter) wr.Write(ControlChars.CrLf & "Log Entry:") wr.WriteLine("(0) {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString()) wr.WriteLine(" :") wr.WriteLine(" :{0}", logMessage) wr.WriteLine("---------------------------") wr.Flush() End Sub Public Shared Sub LotToEventLog(ByVal errorMessage As String) Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog log.Source = "My Application" log.WriteEntry(errorMessage) End Sub End Class
2) Make & register its assembly, in SQL Server 2005. 3)Create Stored Procedure as given below:
CREATE PROCEDURE dbo.SP_LogTextFile ( @LogName nvarchar(255), @NewMessage nvarchar(255) ) AS EXTERNAL NAME [asmLog].[WriteLog.WLog].[LogToTextFile]
4) When i execute this stored procedure as Execute SP_LogTextFile 'C:Test.txt','Message1'
5) Then i got the following error Msg 6522, Level 16, State 1, Procedure SP_LogTextFile, Line 0 A .NET Framework error occurred during execution of user defined routine or aggregate 'SP_LogTextFile': System.UnauthorizedAccessException: Access to the path 'C:Test.txt' is denied. System.UnauthorizedAccessException: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, ileOptions options) at System.IO.StreamWriter.CreateFile(String path, Boolean append) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) at System.IO.StreamWriter..ctor(String path, Boolean append) at System.IO.File.AppendText(String path) at WriteLog.WLog.LogToTextFile(String LogName, String newMessage)
I'm trying to create a proc for granting permission for developer, but I tried many times, still couldn't get successful, someone can help me? The original statement is:
Can I dynamically (from a stored procedure) generatea create table script of all tables in a given database (with defaults etc)a create view script of all viewsa create function script of all functionsa create index script of all indexes.(The result will be 4 scripts)Arno de Jong,The Netherlands.
I have some code that dynamically creates a database (name is @FullName) andthen creates a table within that database. Is it possible to wrap thesethings into a transaction such that if any one of the following fails, thedatabase "creation" is rolledback. Otherwise, I would try deleting on errordetection, but it could get messy.IF @Error = 0BEGINSET @ExecString = 'CREATE DATABASE ' + @FullNameEXEC sp_executesql @ExecStringSET @Error = @@ErrorENDIF @Error = 0BEGINSET @ExecString = 'CREATE TABLE ' + @FullName + '.[dbo].[Image] ( [ID][int] IDENTITY (1, 1) NOT NULL, [Blob] [image] NULL , [DateAdded] [datetime]NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]'EXEC sp_executesql @ExecStringSET @Error = @@ErrorENDIF @Error = 0BEGINSET @ExecString = 'ALTER TABLE ' + @FullName + '.[dbo].[Image] WITHNOCHECK ADD CONSTRAINT [PK_Image] PRIMARY KEY CLUSTERED ( [ID] ) ON[PRIMARY]'EXEC sp_executesql @ExecStringSET @Error = @@ErrorEND
I'm looking for a simple way to create a text file inside a stored procedure. I want to set it up so the end user would just execute the SPROC that would run the required queries and dump the result into a custom formated text file.
I tried BCP but could not lauch it inside the SPROC without using OSQL. I am running SQL Server 2003 64bit. Any ideas?
I'm using an ISP with SQL Server, the Database Publishing Wizard worked great to create a text.sql file which recreated the exact replica of the local db on the ISP's SQL Server. But, is there a code library for this somewhere so I can run this automatically on the the server and post the text.sql file off as a local backup?
Hi everibody. My name is Ivan and I am from Slovakia. I would like to ask you all for helping me in creating a full text search in database. I am working in Visual Web Developer 2005. I have a simple table in wich i have this atributes: ID, NAME, DESCRIPTION, CONTENT I would like to use the search for this: When I write down for example a NAME to a textarea (whatever else it can be), I need to get back the information about the ID of the apropriate NAME. I would really appreciate your help here. Please can you send me a mail with the solution or any help on ivoporsche@szm.sk Thank you very much in advance.
We are using an old version of Numara TrackIT for our helpdesk software, and it doesn't have much in the way of configurable options. There is no way to set validation or formatting on the text fields in the program.
There is a field, WO_TEXT1, Which I would like to be formatted as 6 characters, 3 integers + a period + 2 integers. The first the integers would be padded with zeros on the left, and the last 2 integers would be padded with zeros on the right.
IE, if someone enters 2, it would actually end up being 002.00 If someone enters 3.5 it would end up being 003.50 If someone enters 12.1 it would end up being 012.10 If someone enters 172.80 it would end up being 172.80
I was hoping to achieve this via an update trigger.
Below is the guts of the trigger I created, mostly as a proof of concept.
-- This update properly formats the Estimated Hours field Update t SET WO_TEXT1 = (SELECT RIGHT('000000' + CONVERT(VARCHAR(6), WO_TEXT1), 6) FROM inserted) FROM dbo.TASKS as t Where (EXISTS (SELECT * FROM inserted WHERE WOID = 24773));
I expected that this update trigger would only affect the Work Order with a WOID of 24773. Unfortunately, it updated all 21000 work orders in our system, wiping out all of the actual estimated hours that had been inserted by technicians!
Luckily I had a report that I could quick dump the 300 or so active work order's estimated hours back into the DB from (all the other Work orders are closed, and no one really cares about their estimated hours).
My question is three fold,
1) Why did my trigger update every record in the tasks table instead of just WO 24773? 2) Is using a trigger the best way of accomplishing what I'm trying to do? 3) if a trigger is the best way of accomplishing this, what should my trigger look like?
I need to get a list of customer ids and then use them as a parameter to select from a transaction table and then create a file for each customer. I have used an execute SQL task to get the list of customers and have put the result set into a variable.
How do go through the recordset to create a file for each customer?
Since my experience in VS is extremely limited, i'd like to be exused if questions sound silly.
My problem is that, at my device application project, i want to build a database that will retrieve data from .xls, or .csv, or .txt, or .mbd files. If i've noticed well, there is no support for OLEDB or ODBC, since by the time that i add tableadapter to my database.xsd and use these, after insertion i get multiple errors informing that system.data.oledb. .... or .odbc "type is not defined".
If it cannot be done, and since i still try to figure out how smart devices function, transact with databases, e.c.t. is there any suggestion?
For reasons that are not relevant (though I explain them below *), Iwant, for all my users whatever privelige level, an SP which createsand inserts into a temporary table and then another SP which reads anddrops the same temporary table.My users are not able to create dbo tables (eg dbo.tblTest), but arepermitted to create tables under their own user (eg MyUser.tblTest). Ihave found that I can achieve my aim by using code like this . . .SET @SQL = 'CREATE TABLE ' + @MyUserName + '.' + 'tblTest(tstIDDATETIME)'EXEC (@SQL)SET @SQL = 'INSERT INTO ' + @MyUserName + '.' + 'tblTest(tstID) VALUES(GETDATE())'EXEC (@SQL)This becomes exceptionally cumbersome for the complex INSERT & SELECTcode. I'm looking for a simpler way.Simplified down, I am looking for something like this . . .CREATE PROCEDURE dbo.TestInsert ASCREATE TABLE tblTest(tstID DATETIME)INSERT INTO tblTest(tstID) VALUES(GETDATE())GOCREATE PROCEDURE dbo.TestSelect ASSELECT * FROM tblTestDROP TABLE tblTestIn the above example, if the SPs are owned by dbo (as above), CREATETABLE & DROP TABLE use MyUser.tblTest while INSERT & SELECT usedbo.tblTest.If the SPs are owned by the user (eg MyUser.TestInsert), it workscorrectly (MyUser.tblTest is used throughout) but I would have to havea pair of SPs for each user.* I have MS Access ADP front end linked to a SQL Server database. Forreports with complex datasets, it times out. Therefore it suit mypurposes to create a temporary table first and then to open the reportbased on that temporary table.
use AFMIF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name='uye_idler') drop table uye_idlerCREATE TABLE uye_idler ( uye_no int NOT NULL, ) GO DECLARE @uye_numarası int Set @uye_numarası = 1 WHILE @uye_numarası < 15001 BEGIN INSERT INTO uye_idler VALUES (@uye_numarası) Set @uye_numarası = @uye_numarası + 1 EndHi , I am able to create 15000 records by the codes above .By the same way I want to create random texts as ASD ,WER,SAD,DFG etc. How can I do this ? Thanks ...
Is it possible to create a stored procedure which will create a text file (containing information from some tables) and send it via e-mail to a list of user.
I know that I will have to configure the SQL Mail.
If it is possible, can someone give me sample code.
How can we create a DB for a single attribute such as ORDER DETAILS, CASH RECEIPT, TAX INVOICE having more than 2 text fields.
Also, in every form attribute such as order id is not present - in order identify the same as a primay key. So, which other attributes or fields can be considered as a primary key.
Hope this is the right forum - apologies if its not. I'm a newbie. I'm at my wits end as I cant create a full-text catalog in SQL server 2000. Let me explain (I'll try and include as much info as I can):-
When I run the following command: sp_fulltext_catalog 'Cat_Desc', 'create'
I get the following error mesaage:
Server: Msg 7619, Level 16, State 2, Procedure sp_fulltext_catalog, Line 64 The specified object cannot be found. Specify the name of an existing object.
I in as user sa. I determine this from running: select suser_sname()
The SQL Server instance is running under user: LocalSystem I determine this from the following command:
I am trying to create a text file from an SQL query on a SQL table. I would like the SSIS package to prompt for the file name and path. The text file is tab delimited and the text qualifier is a double quote.
When I try to create a full-text catalog on my local database I get an error that I can not find support information for.
Here is the command I run :CREATE FULLTEXT CATALOG asset_search_values_catalog on FILEGROUP ftFileGroup IN PATH 'C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLData' as default
Here is the error message I get: Msg 7689, Level 16, State 1, Line 1 Execution of a full-text operation failed. 'No such interface supported'
I check the properties of my database and Full-text is enabled.
I am running SQL Server 2005, on an XP Pro, SP2. I had originially installed in side by side with SQL Server 2000.
I even tried uninstalling SQL Server 2005 (to try a re-install), I could not even uninstall the database.
Hello all I have a sql file that I want execute by using the cmdsql command line. But when I create a text file I receive two Informational Messages: 1. "Changed database context to 'DataBaseName'." 2. (2 row(s) affected) How can I ignore these messages in my text file? there is a parametter or something elese to configure to avoir these Informational Messages?
Hi, I want to execute some queries inside a stored procedure, get the data and create from them some strings with formatted parts (bold, italic, underline, different color fonts) and save them in a text field. These strings are going to be displayed in some DBRichText control in a database application built with Delphi. Is there an easy way to create these complex rtf formats in MSSQL or some ideas regarding this problem?
I tried too much to create FULL TEXT INDEX by using SQL Server 2005 Management Studio Express, it returns this ERR MSG:
Informational: No full-text supported languages found. Informational: No full-text supported languages found. Msg 7680, Level 16, State 1, Line 1 Default full-text index language is not a language supported by full-text search
This problem dos not come when I use Microsoft SQL Server 2005 Management Studio, to create FULL TEXT INDEX!
My DB collation is: "Arabic_CI_AS" But I don€™t need this, I can use English Language.
I have a pivot table that connects to our data warehouse via a PowerPivot connection. Â The data contains a bunch of comment fields that are each between 250 and 500 characters. Â I've set the columns in this pivot table to have the 'Wrap Text' set to true so that the user experience is better, and they can view these comment fields more clearly.
However, whenever I refresh the data, the text wrapping un-sets itself. Â Interestingly, the 'Wrap Text' setting is still enabled, but I have to go and click it, then click it again to actually wrap the text. Â This is very burdensome on the user, and degrading the experience.
Any way to make this text wrapping stick so that I don't have to re-set it every time I refresh the data?
LEFT OUTER JOIN vwInventoryAllocMapping AS vwMap ON a.TNRAllocTypeID = vwMap.TNRInventoryAllocID
LEFT OUTER JOIN ABC.dbo.ZREFRESHTAB AS b ON a.DispenserID = b.Asset
LEFT OUTER JOIN ABC.dbo.TableJoinKey AS c ON a.TitleID = c.TITLE_ID
WHERE (vwMap.DataSourceID = 3) and vwMap.[DataSourceAllocName] = 'I'
group by c.SKU_NO , vwMap.[DataSourceAllocName],a.Qty , b.Profit_Center
order by c.SKU_NO,vwMap.[DataSourceAllocName]
GO
i have to send the result of aforesaid script in batch of 300 records per file (tab delimited text file) now the file name must be dynamically created as each file will contain 300 records.
I have found some document related to same issue on this url