Create Fiat File Using Trigger in SQL Server
Dear All,
How to Create a Flat File using Trigger in SQL Server?
Take a look at osql/sqlcmd, bcp, COM calls, xp_cmdshell, etc. Here are a few links with code examples:
https://www.simple-talk.com/sql/t-sql-programming/reading-and-writing-files-in-sql-server-using-t-sql/
http://www.nigelrivett.net/SQLTsql/WriteTextFile.html
http://stackoverflow.com/questions/8132663/creating-a-text-file-on-local-machine-using-sql-server-2008
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
How to load decimal values into a file using bcp in SQL Server 2000?
Hi everyone,
I'm trying to load data from a database table to a text file using bcp on SQL Server 2000. When I'm loading the decimal values, the values before the decimal are not being loaded into the file. How could I load the values before decimals?
Here are the DDLs and DMLs of what I'm trying to run:
CREATE TABLE [dbo].[Product_Sales](
[Year_of_Sale] [smallint] NOT NULL,
[Product_Type] [varchar](25) NOT NULL,
[Product_Group] [varchar](25) NOT NULL,
[Category_Type] [varchar](25) NOT NULL,
[Category_Group] [varchar](10) NOT NULL,
[Product_Count] [bigint] NOT NULL,
[Product_Amount] [decimal](19, 2) NOT NULL,
[Category_Count] [bigint] NOT NULL,
[Category_Amount] [decimal](19, 2) NOT NULL,
CONSTRAINT [PK_Product_Sales] PRIMARY KEY CLUSTERED
[Year_of_Sale] ASC,
[Product_Type] ASC,
[Product_Group] ASC,
[Category_Type] ASC,
[Category_Group] ASC
) ON [PRIMARY]
) ON [PRIMARY]
INSERT INTO [Yearly_Sales].[dbo].[Product_Sales]
VALUES(2010, 'Online', 'Web', 'Cameras', 'Electronics', 547, 0.00, 0, 0.00)
EXEC [master].[dbo].[xp_cmdshell] 'bcp "SELECT * FROM [Yearly_Sales].[dbo].[Product_Sales]" queryout D:\Yearly_Sales\Product_Sales.dat -c -T -S'
And the output I see in the file is:
2010 Online Web Cameras Electronics 547 .00 0 .00
The values before decimals are being truncated.
Thanks,
Bangaaram
Known is a DROP, Unknown is an OCEAN.You can modify the decimal column(s) in the table to varchar type before export. But it does not look good.
alter table [dbo].[Product_Sales]
Alter column [Product_Amount] varchar(20)
alter table [dbo].[Product_Sales]
Alter column [Category_Amount] varchar(20)
Does that make any sense?
Known is a DROP, Unknown is an OCEAN.
Basically you modify the decimal column to a varchar type before you run the bcp command for export. You can modify your source table or you can modify them on the fly. It is just a workaround.
Modifying the source wouldn't be a good idea. Never do that if you can't get your desired output.
Known is a DROP, Unknown is an OCEAN. -
Introduction
In SQL Server Analysis Services (SSAS), you can create a calculated measure in SQL Server Data Tool (SSDT)/Boniness Integrated Development Studio (BIDS). Sometimes you may need to create calculated measure by using AMO in a C# or VB project.
In this article, I will demonstrate so how to create calculated measure using AMO in SSAS?
Prerequisites
Before create calculated measure using AMO, you need to ensure that the following components were installed in your server.
The multidimensional database AdventureWorks Multidimensional Model 2012
A SQL Server with SSIS and SSAS installed
The AMO libraries installed:
X86 Package (SQL_AS_AMO.msi)
X64 Package (SQL_AS_AMO.msi)
Solution
Here is the detail steps to create calculated measure using AMO in SSAS.
Open SSDT and create a new SSIS project.
Drag Script Task to the design surface.
Click SSIS-> Variables to open the Variables window and add two variables that used to connect to the server and database.
Create a connection to connect to SSAS server.
Rename the connection name to ssas.
Double click the Script Task to open Script Task Editor.
Add Connection and Database variables to ReadWriteVariables textbox and then click Edit Script button.
Add AMO reference in the Solution Explore window.
Copy the script below and paste it into the script.
Dim objServer As Server
Dim objDatabase As Database
Dim strDataBaseID As String
Dim objCube As Cube
Dim objMdxScript As MdxScript
Dim objCommand As Command
Dim strCommand As String
objServer = New Server
objServer.Connect("localhost")
objDatabase = objServer.Databases("AdventureWorksDW2012Multidimensional-EE2")
strDataBaseID = objDatabase.ID
If objDatabase.Cubes.Count > 0 Then
objCube = objDatabase.Cubes("Adventure Works")
If objCube.MdxScripts.Count > 0 Then
objMdxScript = objCube.MdxScripts("MdxScript")
objMdxScript = objCube.MdxScripts(0)
Else
objCube.MdxScripts.Add("MdxScript", "MdxScript")
objMdxScript = objCube.MdxScripts("MdxScript")
End If
objCommand = New Command
strCommand = "CREATE MEMBER CURRENTCUBE.[Measures].[Multipy Measures By 3]"
strCommand = strCommand & " AS [Measures].[Internet Sales Amount] * 3, "
strCommand = strCommand & " VISIBLE = 1 ; "
objCommand.Text = strCommand
objMdxScript.Commands.Add(objCommand)
objMdxScript.Update()
objCube.Update()
End If
objServer.Disconnect()
Then you can run this SSIS package to create the calculated measure.
Applies to
Microsoft SQL Server 2005
Microsoft SQL Server 2008
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2012
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Thanks,
Is this a supported scenario, or does it use unsupported features?
For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
in a supported way?
Thanks! Josh -
Query on text file using Openrowset in Sql server 2012
Hi,
I am using below query on Sql server 2008 and sql server 2012.It is working find in 2008 but giving error in 2012.
below is query and error on sql 2012
select * from OpenRowset('MSDASQL', 'Driver={Microsoft Access Text Driver (*.txt, *.csv)};DefaultDir=D:\MSSQL;',
'select * from employee1.txt')
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".
I have read some document on msdn and install microsoft access database engine 2010, but still it not working.
Can anyone suggest resolution of this problem.
Thanks
Shitalkumar kasliwalRead this link
http://calyansql.blogspot.co.il/2013/02/fix-cannot-initialize-data-source.html
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Hello All:
I have an requirement of generating a PDF file using Oracle PL SQL program. Can anyone please let me know the procedure/code of doing this?
Thanks,
k Ramesh GuptaI have steps to generate Excel sheet output, apply appropriate content-type for PDF in the PL/SQL written below, to get the same in PDF. i suppose it should be application/pdf
1. Create a custom DAD if required using Enterprise Manager Console of MidTier for HTTP Server or use Portal DAD itself to implement the solution.
2. Create a new procedure (a webdb solution) to stream the HTML for the excel sheet report which will be downloaded.
a. Login to Portal schema through SQL*Plus or the respective DAD based schema if custom DAD is created. (below example is created in custom DAD - 'scott').
SQL>CREATE OR REPLACE
PROCEDURE generateCsv
as
cursor p_emp is select * from PORTAL_DEMO.EMP;
begin
owa_util.mime_header( 'application/vnd.ms-excel', False ); -- Here change the content-type to PDF Format accordingly
htp.print('Content-Disposition: attachment;filename="pvasista.csv"');
owa_Util.Http_Header_Close;
for v_emp_cur in p_emp
LOOP
htp.p (v_emp_cur.ename || ',' || v_emp_cur.deptno || chr(13));
END LOOP;
end;
SQL> grant execute on generateCsv to public;
For education purpose getting the report of employee and deptno of al employees from PORTAL_DEMO.EMP table. Implement the necessary query/ Business Logic accordingly.
b. Now access http://midtier_host:port/pls/dad_name/generateCsv, will download a .csv based excel file report as shown in the screenshot below,
3. Open the Portal Page where the link is to be added, createa URL Item Link and add the above URL, select option "Open in new browser window"
4. It can also be enhanced to have filtering enabled on the report by using Portal Form using Option, "Form based on stored procedure" and selecting the above stored procedure. -
How to create database link between oracle and SQL Server
Hello Everyone,
Here i have Oracle Database 9i and SQL Server 2005 databases.
I have some tables in sql server db and i want to access from Oracle.
How to create a database link between these two servers
Thanks,Thanks for Everyone,
I was struggle with this almost 10 days....
I created Database link from Oracle to SQL Server
Now it is fine.........
Here i am giving my servers configuration and proceedure how i created the db link...@
Using Generic Connectivity (HSODBC) we can create db link between Oracle and SQL server.
Machine (1)
DB Version : Oracle 9.2.0.7.0
Operating System : HP-UX Itanuim 64 11.23
IP : 192.168.0.31
Host : abcdbt
Machine (2)
Version : SQL Server 2005
Operating System : Windows server 2003 x86
IP : 192.168.0.175
Host : SQLDEV1
User/PW : sa/abc@123! (Connect to database)
Database : SQLTEST (exsisting)
Table : T (“ T “ is the table existing in SQLTEST database with 10 rows)
Prerequisites in Machine (2):
a) Oracle 10g software
b) User account to access SQL Server database (sa/abc@123!)
c) Existing SQL Server Database (SQLTEST)
d) Tables (testing purpose) (T)
Steps:
1) Install Oracle 10.2.0.1 (Only SW,No need of database) *(Machine 2)*
2) Create a DSN where your windows Oracle 10g SW resides *(Machine 2)*
Control panel >> Administrative Tools >> Data Source (ODBC) >> System DSN ADD
You can follow this link also.....
http://www.databasejournal.com/features/oracle/article.php/3442661/Making-a-Connection-from-Oracle-to-SQL-Server.htm
I created DSN as
DSN name : SQLTEST
User : SA/abc@123! (Existing user account)
Host : 192.168.0.175 (machine 2)
Already I have 1 database in SQL Server with the name SQLTEST
You can create DSN with different name also (not same as db name also)
3) Create a hsodbc init file in $ORACLE_HOME\hs\admin *(Machine 2)*
Create init<DSN NAME> file
Ex: initSQLTEST
Copy inithsodbc to initSQLTEST
And edit
initSQLTEST file
HS_FDS_CONNECT_INFO = SQLTEST <DSN NAME>*
HS_FDS_TRACE_LEVEL = OFF*
save the file....@
4) Configure Listener.ora *(Machine 2)*
LISTENER_NEW =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.175)(PORT = 1525))
SID_LIST_LISTENER_NEW =
(SID_LIST =
(SID_DESC =
(SID_NAME = SQLTEST) *+< Here SQLTEST is DSN NAME >+*
(ORACLE_HOME = G:\oracle 10g\oracle\product\10.2.0\db_1)
(PROGRAM = hsodbc))
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = G:\oracle 10g\oracle\product\10.2.0\db_1)
(PROGRAM = extproc) )
:> lsnrctl start LISTENER_NEW
5) Configure tnsname.ora *(Machine 2)*
SQLTEST11 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.175)(PORT = 1525))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = SQLTEST))
(HS=OK)
:> tnsping SQLTEST11
If No errors then conti….
6) Configure a file *(Machine 1)*
Cd $TNS_ADMIN ($ORACLE_HOME/network/admin)
Create a file
$ vi TEST_abcdbt_ifile.ora
something=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST =192.168.0.175) (PORT=1525))
(CONNECT_DATA=
(SID=SQLTEST))
(HS=OK)
$ tnsping something
$ sqlplus system/manager
Your connected to Oracle database *(machine 1)*
create database link xyz connect to “sa” identified by “abc@123!” using ‘SOMETHING’;
select * from t@xyz;10 rows selected.
Thanks,
Edited by: ram5424 on Feb 10, 2010 7:24 PM -
Hibernate mapping XML files for the two SQL Server tables below.
Hello all..,
Question 1:
I am working on a project that needs to support a database with an inherited legacy schema that you cannot change. The schema is provided below.Hibernate mapping XML files for the two SQL Server tables below. Please provide those two XML files. Assume some hypothetical package and class names. Assume that no "fancy" stuff such as lazy initialization, optimistic locking etc is needed at this time.
CREATE TABLE [SURVEY_ANSWERS] (
[ANSWER_ID] [int] IDENTITY (1,1) NOT NULL,
[QUESTION_ID] [int] NOT NULL,
[POSITION] [int] NULL,
[TEXT] [varchar](350) NULL
CREATE TABLE [dbo].[SURVEY_QUESTIONS] (
[QUESTION_ID] [int] IDENTITY (1, 1) NOT NULL ,
[TEXT] [varchar] (350) NULL
GO
ALTER TABLE SURVEY_ANSWERS
ADD CONSTRAINT pk_SURVEY_ANSWERS PRIMARY KEY(ANSWER_ID,QUESTION_ID);
ALTER TABLE [dbo].[SURVEY_QUESTIONS] ADD
PRIMARY KEY CLUSTERED
[QUESTION_ID]
GO
ALTER TABLE [dbo].[SURVEY_ANSWERS] ADD
FOREIGN KEY
[QUESTION_ID]
) REFERENCES [dbo].[SURVEY_QUESTIONS] (
[QUESTION_ID]
)Question 2:
Assume that you are working on a project developing, say, a banking application. You are the Architect and thinking that Hibernate ORM should be used for the entire access to the relational database. As usual, you have created (or auto-generated) a set of HBM XML files as well as POJOs for which you define the mappings. Assume now that a new requirement has just popped up. The system needs to be able to import new bank accounts and user information in bulk from a very large XML file at once and store it in the database. Assume the XML file contains all necessary information to populate fields in database tables. As performance is very important for this operation. Given this description, how would you approach the problem?
Please describe briefly.
-Thanks and regards
Praveen SoniYou're not fooling anyone Dennis_Mox. But nice try.Jeez, man. Mail me at denismox[at]yandex.ru, I will show you that exact test, dammit.
-
Can't create a file using fm 'File_Get_Name'
hi gurus,
Can you please help me with this issue. There's a program that have to create a file using the said fm. It was working before when it was set in OS NT. But when the settings and codes have been changed to UNIX, the program was able to generate the program. But the file doesn't exist. It seems it doesn't create a file in that server.
What else do I need to check?
Points will be rewarded. Thanks
Here's the code for your reference:
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
* CLIENT = SY-MANDT
logical_filename = 'Z_SYSBRIDGE'
OPERATING_SYSTEM = SY-OPSYS
* PARAMETER_1 = ' '
* PARAMETER_2 = ' '
* USE_PRESENTATION_SERVER = ' '
* WITH_FILE_EXTENSION = ' '
* USE_BUFFER = ' '
IMPORTING
* emergency_flag =
* file_format =
file_name = ltfile-out_path
EXCEPTIONS
file_not_found = 1
OTHERS = 2.Hi Maui,
Did you check SM69, where the code that ties to this FM creates a file after it execute your FM...
SM69 are os commands that does UNIX execution or other OS commands...
or maybe you have missed another FM like FM 'SXPG_OS_COMMAND' or of some sort.
Thanks
William Wilstroth -
How to write a file using mod pl/sql
hi,
i am having a submit button in my procedure. which should inturn create .sql file in a file path.
is there any way to create a fileusing htp and htf methods.
Thanks in advance
Hari>
i am having a submit button in my procedure. which should in turn create .sql file in a file path.
is there any way to create a file using htp and htf methods.
>
Why are you wasting your time coding from scratch using the PL/SQL Web Toolkit instead of the APEX framework?
From Re: how to write a file using mod pl/sql it appears that you are not using APEX, so a number of the approaches APEX offers are not relevant. You appear to be looking for a file download solution using the <tt>wpg_docload.download_file</tt> method, such as:
create or replace procedure download_file (
p_filename in varchar2
, p_mimetype in varchar2
, p_content in out nocopy blob)
is
begin
-- Set up HTTP header.
-- Use "application/octet" as default MIME type.
owa_util.mime_header(nvl(p_mimetype, 'application/octet'), false);
-- Set the size so the browser knows how much to download.
htp.p('Content-length: ' || dbms_lob.getlength(p_content));
-- Filename will be used as default by the browser in "Save as..."
htp.p('Content-Disposition: attachment; filename="' || p_filename || '"');
-- Close header.
owa_util.http_header_close();
-- Stream the file content to the browser.
wpg_docload.download_file(p_content);
end download_file; -
Creating a datasource to connect MS SQL server
I am using CF 7 and trying to create a datasurce to connect
to my MS SQL server database.
I get the following error when trying to create a Datasource:
I have tried using the MS SQL server driver and also using
Other
I continue to get the error:
java.sql.SQLException: [Macromedia][SQLServer JDBC
Driver][SQLServer]Login failed for user 'trubel'. Reason: Not
associated with a trusted SQL Server connection.
The root cause was that: java.sql.SQLException:
[Macromedia][SQLServer JDBC Driver][SQLServer]Login failed for user
'trubel'. Reason: Not associated with a trusted SQL Server
connection.
Can anyone help me?
Tim Rubel
AIM: unixsyadmTo set up Windows Authentication Mode security with
Enterprise Manager in SQL Server:
Expand a server group.
Right-click a server, and then click Properties.
On the Security tab, under Authentication, click Windows and
SQL Server Authentication.
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/instsql/in_runsetup_6p9v. asp
Ted Zimmerman -
Hi All,
Is it possible to create a two node cluster with SQL server 2012 STD on node1 and SQL Server 2008 ENT on node2 on a Windows server 2012?
aaI think you are confused with the way cluster is installed. Installing SQL on cluster is a two step process. On first node you create a new SQL cluster and on second node you need "AddNode" action.
Same edition media has to be used in above two operation.
you can install two separate instances with one enterprise and one standard.
Balmukund Lakhani
Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
This posting is provided "AS IS" with no warranties, and confers no rights.
My Blog |
Team Blog | @Twitter
| Facebook
Author: SQL Server 2012 AlwaysOn -
Paperback, Kindle -
Creating new file using report generation express vi
Hello,
In my application, I need to write certain data in excel sheet. For that I created an excel template and I used the express vi in report generation toolkit to save the appropriate data in appropritate columns. I need a new file created everyday by that day's name and write the data to it rest of the day. I am having problems creating new file using this express vi. I tried using the low level vi's but not been able to it properly.
Attaching my code and excel template.
Please help.
Thanks!
Solved!
Go to Solution.
Attachments:
excel write2.vi 119 KB
Book2111.xltx 8 KBr_te wrote:
The thing is everyday there cannot be a file provided.
Sure there can. Don't you see the input on the Express VI for a file? "Path To Save Report" is the name of the input you want.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How to import data from a text file through DTS to Sql Server
Please don't mistake me as i'm a new comer to sql server,please help me.
how to import the data present in a plain text file through DTS into sql server and store the data in a temporary table.
How far the temporary table is stored in the database.
Please reply me as soon as possible.
Thank you viewers.>
I can say that anybody with
no experience could easily do an export/import in
MSSQLServer 2000.
Anybody with no experience should not mess up my Oracle Databases ! -
I am trying to find out how to assign files with particular extensions to the appropriate software. At the moment when I create a file using Word it is apparently given the extension .docx but Word doesn't recognise its own files. How do I allocate the extension .docx to Word? There used to be a way of doing it, I think under "Preferences" but I can't seem to find it.
Still in the same location:
File > Get Info > Open with (select) > Change All (button) -
Since installing Word 2010 (upgrading from Word 2003) there are no visable PDF Icons nor ability to create PDF Files using Adobe Acrobat 6.06. Operating system is Windows XP. Browser is IE8. Various attempts to bypass this situation have not been successful. No problems had been experienced earlier using Acrobat 6.01 through 6.06 with Word 2003 and earlier Word versions during the passed 10 years or so. Adobe's support is not responding to recognize mentioned situations, nor is there any a solution to fix the problem. Low volume small businesses,with limited need to create PDF files, are being considerably burdened to substante a $200 investment to upgrade to Acrobat X, which may as well not be the solution. It is appealed for Adobe Forums readers to share similar experiences with possible fixes at hand. Responses will be greatly appreciated. Thank you...
Your response is greatly appreciated, Bernd...
Unfortunately, those of us who milk software packages for eons such as
Acrobat 6.06 Standard, a full version of Acrobat X is quoted to be $299
with no ability to upgrade since 7.0 is the cutoff which remains to be
only $139.
It seems to me, Military personal, retired or just ole toots who did
their think, would offer considerations such as Staples, Lowe's, and
other big boxes offer. Such is greed for some who do not consider
alternatives above their noses...
Thank you,
Skip
Maybe you are looking for
-
Recovery Disk Creator (Express Media Player)
Hello, This is my first visit to these forums. I bought my Toshiba Satellite A105-S4284 laptop back in November 2006 from CompUSA. Recently, I had to take my laptop to a local repair shop because I updated McAfee and the desktop froze- this is jus
-
Put, Get , Connection buttons greyed out
Hi All, I am pretty new to Dreamweaver but not to web development. I have set up and connected a few sites from my own PC. It all goes just like it says in the manuals. But I got called into a client site who have an existing site set up in Dreamweav
-
Using servlet in combination with public_html subfolders
Hi, I'm fairly new to servlet and jsp technology. Up to this point I only really used PHP for developing dynamic web content. But since I have finally been working more with Java I want to start using Java for my web needs as well. So I've started wi
-
Question about SAP Enterprise Services Explorer 1.1
Hi , 1. I use dotnet connector before and now someone told me that I can use SAP Enterprise Services Explorer 1.1 but when I download this app, it says '90 day evaluation '; what about after 90 days? 2. another questions, our
-
Adobe X not allowing me to type
Alright, here's the problem I'm having: Whenever I attempt to type anything or enter a command, the program won't acknowledge it. Ctrl+F should bring up the Find, but it doesn't. If bring it up manually with my mouse, I can't enter anything into th