Writing Errorlog To Sql Errorlog Problem
Jun 14, 2001
Hello all,
I don't know what I am doing wrong.
In my environment, we have monitoring tool that scan through sql errorlog
every 10minutes to capture some error that occurs.
I have been trying for days now to create an alert for any of our failed
backup to appear in the sql errorlog with the code below. After I add
message to the sysmessage table with sp_addmessage, and raising the error
with log option, I modified the existing scheduled backup job by creating
an alert with the num in the code.
For some reason, this error will not just show up in the sql errorlog when
it failed.
Has anyone any advise on what to do?
The code is:
sp_addmessage 50001, 25, 'Backup Failed for the '%.*ls' database.Please Contact MSSQL DBA Immediately!!!! '
GO
DECLARE @DBID INT
SET @DBID = DB_ID()
DECLARE @DBNAME NVARCHAR(128)
SET @DBNAME = DB_NAME()
RAISERROR (50001, 25, 1, @DBID, @DBNAME) with log
GO
Thanks
SA
View 1 Replies
ADVERTISEMENT
Aug 14, 2000
Hi!
Even though i see all the errorlog files physically stored in the log directory, I am not seeing any errorlog info on Enterprice Manager. I see all files like errorlog, errorlog1, errorlog2, etc, when i click current errorlog, it shows nothing, Please help me what could be the problem?
Appreciate all your ideas.
Mohan
View 1 Replies
View Related
Dec 9, 1998
what does the error "login failed-User: Reason : Not associated with a trusted
SQL Server connection" means in the errorlog? it keeps on writing in the errorlog. what could be the caused of this? and how to correct this?
thanks a lot!
View 1 Replies
View Related
Sep 25, 2003
Hi....Does anyone know if there is a similar command to SQL2K's DBCC ERRORLOG.
I'm currently writing a preventative maintenance script and want to force archiving of errorlogs. Any help greatly appreciated.
View 3 Replies
View Related
Aug 13, 2002
Hello-
I am getting a recurring error in my errorlog. This is the error:
"BlkHeader from strip 0 At 13531e00 ExpectedAt 13531e00 Size c00 PrevSize 200"
Has anyone seen this before?
Thanks,
Traci McPartland
View 2 Replies
View Related
Apr 20, 2004
I am trying to change the default number of SQL errorlogs from 6 to 12. Does anyone know how to change that?
View 7 Replies
View Related
Dec 22, 2005
I just spent the better part of a full day trying to figure out why my MSSQLSERVER service wouldn't start. Finally, after someone suggested I check out "C:Program FilesMicrosoft SQL Server[Instance Name]LogErrorLog" I found my problem. I opened it up to find: (newbie mistake, I know now!!)
2005-12-21 19:27:46.60 server SQL Server evaluation period has expired
So I thought I would pass this onto everyone I can think of so you will not make the mistake I just did.
It would have been nice if Microsoft, like just about every other software company out there, would have been loud & obnoxious about their trial software expiring. Instead they have to put a poor newbie soul thru what I just went thru.
*sigh*
Well if I helped 1 person with this, I've done some good!
View 1 Replies
View Related
Sep 17, 2001
I need to move the errorlog files from the d: drive to the e: drive on my NT servers. Does anyone know a way to accomplish this without having to re-install?
Thanks
tcb
View 2 Replies
View Related
Jan 19, 2000
We're running SQL 6.5 SP3, we recycle our SQL server every day, somehow starting last December, the errorlog kept appending to the previous one
without starting a new log, and it keeps on growing,
any one knows anywhere I should look into ?
If SQL behaves properly, it should starts a new log after each recycle.
I checked from Technet this problem may occur in 4.2 but I haven't seen anything in 6.5....Thanks
Anthony
View 3 Replies
View Related
Nov 2, 2004
Considering email is setup, how would you send emails by scanning errorlog for any issues. Also, how to send program outputs using email.
Thanks
View 4 Replies
View Related
Sep 6, 2006
Hi.
I have a service on a server which contains Sql Server Express.
this service adds documents to the database to allow full text search features.
From some reason, the index crashes and than it writes to the ErrorLog file, the errorlog jumps to 20GB(!) causing the server to crash.
How can :
1. limit the size of the error log.
2. find out why the log jumps to this size (I can't open the error log file ofcourse...)
Thanks!
View 5 Replies
View Related
Aug 4, 1999
Hi,
How print out a readable dump by using PRINTDMP, I didn't catch up the
parameters that I have to pass.
Thanks,
Herve Meftah
View 1 Replies
View Related
Feb 28, 2008
We have set up a couple of SQL Server 2005 systems and I have foundthat the format of the ERRORLOG files and the SQL Agent's log filesare Unicode or some format that findstr cannot parse properly. "find"parses them fine, but it doesn't have the capabilities that I need --specifically, I can't search for multiple strings in one search.I see the checkbox on the SQL Agent's for "Write OEM File", but it isgrayed out so I am not able to try checking that. I also don't knowif that would affect the server's ERRORLOG file too or just theAgent's log file.So what am I missing? What is everyone else doing who is used tohaving scripts to parse these files looking for strings that indicateproblems? Is there a server setting that will force it to go back toa plain ANSI text file format for log files? Is that a bad thing todo?Thanks in advance for any insight,Teresa Masino
View 4 Replies
View Related
Dec 1, 2004
Hi
I was not able to connect to SQL Server machine. On examining the Error log (which was huge 53MB), I found the following messages that filled 95% of the logfile. Is this something to do with memory allocation.
Someone, please let me know what is going on. After the server reboot everything works fine.
I am worrired that this message may occur again.
Thanks
Machilu
2004-11-30 20:15:03.64 logon Login failed for user 'NT AUTHORITYSYSTEM'
2004-12-01 08:15:03.77 logon Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
2004-12-01 00:47:25.28 spid70 WARNING: Failed to reserve contiguous memory of Size= 65536.
2004-12-01 00:47:25.31 spid70 Buffer Distribution: Stolen=127590 Free=4176 Procedures=182443
Inram=0 Dirty=14180 Kept=0
I/O=0, Latched=154, Other=10049
2004-12-01 00:47:25.31 spid70 Buffer Counts: Commited=338592 Target=338592 Hashed=24383
InternalReservation=357 ExternalReservation=0 Min Free=256
2004-12-01 00:47:25.31 spid70 Procedure Cache: TotalProcs=66212 TotalPages=182443 InUsePages=88547
2004-12-01 00:47:25.31 spid70 Dynamic Memory Manager: Stolen=310033 OS Reserved=38512
OS Committed=38457
OS In Use=38388
Query Plan=332158 Optimizer=0
General=15540
Utilities=8 Connection=473
2004-12-01 00:47:25.31 spid70 Global Memory Objects: Resource=10685 Locks=119
SQLCache=4540 Replication=2
LockBytes=2 ServerGlobal=45
Xact=201
2004-12-01 00:47:25.31 spid70 Query Memory Manager: Grants=0 Waiting=0 Maximum=92118 Available=92118
2004-12-01 00:50:04.10 logon Login failed for user 'NT AUTHORITYSYSTEM'.
2004-12-01 00:50:04.32 logon Login failed for user 'NT AUTHORITYSYSTEM'.
2004-12-01 00:51:08.78 spid70 WARNING: Failed to reserve contiguous memory of Size= 65536.
2004-12-01 00:51:08.82 spid70 Buffer Distribution: Stolen=138829 Free=5944 Procedures=169283
Inram=0 Dirty=14431 Kept=0
I/O=0, Latched=154, Other=9951
2004-12-01 00:51:08.82 spid70 Buffer Counts: Commited=338592 Target=338592 Hashed=24536
InternalReservation=360 ExternalReservation=0 Min Free=256
2004-12-01 00:51:08.82 spid70 Procedure Cache: TotalProcs=67783 TotalPages=169283 InUsePages=76116
2004-12-01 00:51:08.82 spid70 Dynamic Memory Manager: Stolen=308112 OS Reserved=38512
OS Committed=38457
OS In Use=38398
Query Plan=330249 Optimizer=0
General=15535
Utilities=8 Connection=476
2004-12-01 00:51:08.82 spid70 Global Memory Objects: Resource=10685 Locks=118
SQLCache=4540 Replication=2
LockBytes=2 ServerGlobal=45
Xact=202
View 4 Replies
View Related
Feb 22, 2005
Hi, all
recently, I use the following script(somebody else) to create a database on a remote server: the script is as follow:
/*************************/
CREATE DATABASE [ErrorLog]
GO
Use ErrorLog
CREATE TABLE [dbo].[Errors] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[SessionID] [char] (12) NULL ,
[RequestMethod] [char] (5) NULL ,
[ServerPort] [char] (5) NULL ,
[HTTPS] [char] (3) NULL ,
[LocalAddr] [char] (15) NULL ,
[HostAddress] [char] (15) NULL ,
[UserAgent] [varchar] (255) NULL ,
[URL] [varchar] (400) NULL ,
[CustomerRefID] [varchar] (20) NULL ,
[FormData] [varchar] (2000),
[AllHTTP] [varchar] (2000),
[ErrASPCode] [char] (10) NULL ,
[ErrNumber] [char] (11) NULL ,
[ErrSource] [varchar] (255) NULL ,
[ErrCategory] [varchar] (50) NULL ,
[ErrFile] [varchar] (255) NULL ,
[ErrLine] [int] NULL ,
[ErrColumn] [int] NULL,
[ErrDescription] [varchar] (1000) NULL ,
[ErrAspDescription] [varchar] (1000) NULL ,
[InsertDate] [datetime] NOT NULL
) ON [PRIMARY]
--Create the user "ErrorLog"
if not exists (select * from master.dbo.syslogins where loginname = N'ErrorLog')
BEGIN
declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'Navigator', @loginlang = N'us_english'
if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)
select @logindb = N'master'
if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')
select @loginlang = @@language
exec sp_addlogin N'ErrorLog', 'secret', @logindb, @loginlang
END
GO
if not exists (select * from dbo.sysusers where name = N'ErrorLog' and uid < 16382)
EXEC sp_grantdbaccess N'ErrorLog', N'ErrorLog'
GO
Grant select, insert On Errors to ErrorLog
/***************************/
in my *.asp program, I used the following string to connect to the database on the remote server.
/********
con.open "dsn=ErrorLog;uid=ErrorLog;pwd=secret;"
********/
the following message comes up:
/********/
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E4D)
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'ErrorLog'.
/*********/
what is the problem here?
when I set up dsn ErrorLOG, I used "abc" userID and password "XXX" which is our server database administrator assigned to me. I tested connection in odbc, it is OK
I just don't get, ther user ErrorLog already had login id and granted access to database errorlog. any clue, please help!
Betty
View 6 Replies
View Related
Jun 21, 2008
I have some experience with MS SQL mostly installation, configuration, maintaining, etc. But I am trying to teach myself some TSQL. I have bought a few beginner books and have some test machines. In advance, I appreciate any feedback!
I have a database with two tables. I want to calc the min salary for a class of employees. The "wage" is in one table and the "status" is in another.
USE Database
GO
SELECT MIN(Wage) AS "Min Salary", Status
FROM Employee, Job
WHERE Status = '1'
GROUP BY Wage, Status
GO
The result set brings back all not the "status" class that I want.
Again, I am relatively new so take it easy on me!
Thanks,
grinch
View 4 Replies
View Related
Mar 3, 2008
Hello,
I wrote a stored procedure in SQL 2K5, and I would like to write to the sql log without using a rasieerror function. I just would like to log the sucessfull steps without exiting the proc. I am not sure how to do this. Any help would be appreciated.
Thanks,
Dave
View 3 Replies
View Related
May 13, 2007
Hi,
I am new to this programming and SQL.
I am following the: Lesson 8: Obtaining Data from a SQL Server 2005 Express Edition Database video series. I cannot get the following to write changes to the SQL Database:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BindingSource1.EndEdit()
'CustomerTableAdapter1.Update(MyCompanyDataSet1.Customer)
Dim rowsAffected As Integer = 0
rowsAffected = CustomerTableAdapter1.Update(MyCompanyDataSet1.Customer)
MessageBox.Show(rowsAffected.ToString())
End Sub
End Class
I do get the message box to popup showing 1 row of changes when I make one change, however that change does not get written to the database. Is this enough info to have any idea why?
Thanks
View 1 Replies
View Related
May 17, 2007
I was hoping that someone might be able to help a SQL statement for this, if possible. I have two tables, InvoiceDetails and InvoiceLineItems. What I'd like to do is write a query that will return all invoices, but also return a value InvoiceTotal Based on SUM(InvoiceLineItems.qty * InvoiceLineItems.unitPrice). I've tried a few different methods of writing this, but haven't had much luck. Can anyone shed some light on this for me? Thanks.
View 7 Replies
View Related
Dec 20, 2007
Hi.I realize this may have been asked a thousand times before, but it's still not working for me. I would appreciate any help with it. First, I created a GridView, and from it I created a new SqlDataSource and let it point to the database in C:My ProjectApp_DataASPNETDB.MDF. This automatically created a connectionString in the Web.Config file, saying the following: "R1ASPNETDBConnectionString" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename="C:My ProjectApp_DataASPNETDB.MDF";Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" /> Now when I try to programatically use that connection string, the program crashes. Below is my code: <script runat="server"> String sqlConnectionString = @"Data Source=.SQLEXPRESS;AttachDbFilename="C:My ProjectApp_DataASPNETDB.MDF";Integrated Security=True;Connect Timeout=30;User Instance=True";
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection conn = new SqlConnection(sqlConnectionString)) { conn.Open(); const String selectQuery = "SELECT StatusName FROM Status ORDER BY StatusName"; Label1.Text = ""; using (SqlCommand cmd = new SqlCommand(selectQuery, conn)) { SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { Label1.Text += dr[0]; while (dr.Read()) { Label1.Text += ", "; Label1.Text += dr[0]; } Label1.Text += ". "; } else
Label1.Text = "None."; } if (conn != null) conn.Close(); } } Here's the error message I'm getting: Server Error in '/My Project' Application.
Keyword not supported: 'c:my projectapp_dataaspnetdb.mdf";integrated security'.
Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details: System.ArgumentException: Keyword not supported: 'c:my projectapp_dataaspnetdb.mdf";integrated security'.
Source Error:
Line 15: protected void Page_Load(object sender, EventArgs e)Line 16: {Line 17: using (SqlConnection conn = new SqlConnection(sqlConnectionString))Line 18: {Line 19: conn.Open();
Source File: c:My Project est.aspx Line: 17
Stack Trace:
[ArgumentException: Keyword not supported: 'c:my projectapp_dataaspnetdb.mdf";integrated security'.] System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +417 System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +99 System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +52 System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +25 System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +141 System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +38 System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4 System.Data.SqlClient.SqlConnection..ctor(String connectionString) +21 ASP.test_aspx.Page_Load(Object sender, EventArgs e) in c:My Project est.aspx:17 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45 System.Web.UI.Control.OnLoad(EventArgs e) +80 System.Web.UI.Control.LoadRecursive() +49 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3745 My question is: How should I write the connection string? I have a feeling the problem is with the quotes ("), but I can't figure out how to write it otherwise.Thank you very much.
View 2 Replies
View Related
Jan 22, 2008
Hello, I have two tables: Customer Training Requests has say two columns.Customer - Class Requested a 1b 1c 1a 2b 2c 3a 3 I have another table called packages, which has packages of class.Package No. Class1 11 2 I want to write a query which will return only those customers who have requested exactly the classes in a particular package.so in above example if the package is 1 the query should return only customer b as only customer b has requested class 1 and 2. Any suggestions? Thanks,Paresh.
View 8 Replies
View Related
Feb 4, 2008
hi, I'm trying to write to a database from a web page. The code is throwing back no errors but it just isn't writing to the database. Am I missing something? void SubmitDetails(Object s, EventArgs e) { SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); SqlCommand objCmd; objCmd = new SqlCommand( "INSERT INTO Member_Information (Name, Address_Line_1, Address_Line_2, Address_Line_3, Email_Address, Contact_Number, " + "Password, Name_Of_Bank, Account_Number, Sort_Code, Bank_Address_Line_1, Bank_Address_Line_2, Bank_Address_Line_3) " + "VALUES (@Name, @Address_Line_1, @Address_Line_2, @Address_Line_3, @Email_Address, @Contact_Number, " + "@Password, @Name_Of_Bank, @Account_Number, @Sort_Code, @Bank_Address_Line_1, @Bank_Address_Line_2, @Bank_Address_Line_3)", objConn); objCmd.Parameters.AddWithValue("@Name", txtName.Text); objCmd.Parameters.AddWithValue("@Address_Line_1", txtAL1.Text); objCmd.Parameters.AddWithValue("@Address_Line_2", txtAL2.Text); objCmd.Parameters.AddWithValue("@Address_Line_3", txtAL3.Text); objCmd.Parameters.AddWithValue("@Email_Address", txtEmail.Text); objCmd.Parameters.AddWithValue("@Contact_Number", txtContact.Text); objCmd.Parameters.AddWithValue("@Password", txtPassword.Text); objCmd.Parameters.AddWithValue("Name_Of_Bank", txtBank.Text); objCmd.Parameters.AddWithValue("Account_Number", txtAN.Text); objCmd.Parameters.AddWithValue("@Sort_Code", txtSort.Text); objCmd.Parameters.AddWithValue("@Bank_Address_Line_1", txtBA1.Text); objCmd.Parameters.AddWithValue("@Bank_Address_Line_2", txtBA2.Text); objCmd.Parameters.AddWithValue("@Bank_Address_Line_3", txtBA3.Text); objConn.Open(); objCmd.ExecuteNonQuery(); objConn.Close(); }
View 4 Replies
View Related
Feb 23, 2008
Hello, how can do the following using sql:
if exists(select * from siteindex where site_url like '%msn.com')ThenUpdate siteindex Set dmodified = GetDate(), isFullPage = 0, fp_flname = 'filename', fp_iWidth = 800, fp_iheight = 600
Where site_url = '%msn.com'
else
insert into siteindex (site_url, dcreated, dmodified, isFullPage, fp_flname, fp_iWidth, fp_iHeight)
Values ('msn.com', GetDate(), GetDate(), 0, 'filename', 800, 600)
I cant get the syntax right. Thanks!
View 1 Replies
View Related
Apr 28, 2008
Hi all,
I have a problem with retrieving data from lookup tables. Ok here is the issue I have a Tables ...
Tables | Schools StuAccount
Fields | Sch_Id (pk) Student_ID (pk)
School_Name AccountableSch_Id
DistrictName TestedSch_Id
ParticipatedSch_Id
Ok, so i have two tables Schools and StuAccount, each has one primary key and and the StuAccount has three foreign keys that associates to the Schools TABLE which has a the definition of school names wich i want to retrieve for all three foreign key in the stuaccount table. Here is what i want ....
Student_ID
AccountableSch_Id
Shool_Name( this the name of the AccountableSch_Id )
TestedSch_Id
Shool_Name( this the name of the TestedSch_Id)
ParticipatedSch_Id
Shool_Name( this the name of the ParticipatedSch_Id)
I just want to look up the id and put the school name in the final resulting join and i have no idea how to lookup the table School three time and put school name for all three foreign keys.??
Any help will be much appreciated.
Thanks
View 4 Replies
View Related
Jun 5, 2008
Hey everyone,
I'm making a site and I need to write some code that will do the following things:
Write a statement for the Page_Load event to pull the information from the db and load it into a textbox and a textbox with multiline attribute.
View 13 Replies
View Related
Nov 20, 2003
Please find the necessary SQL scripts to generate a small version of my database and some data at the bottom of this post.
Here's a short description of what the database is all about: It's a project tracking and management system. Contracts go into the tblDeals table. Because each project may be different in nature, project phases are defined in tblPhaseType and tblPhase tables. The table used to keep track of what's going on is the tblProduction table.
Here's what I need to do. When a project is completed -- meaning it has gone through all the phases that it needs to go through -- I want a trigger to fire up and change the contract status in the tblDeals table to "Completed" whose value is 1. When a new contract gets entered into the table, the Contract Status is set to 5 by default which means "In Progress" -- as defined in tblContractStatus. The tricky part is that because, each project is different and has different number of phases, the trigger has to make sure that all the phases have been submitted into the tblProduction table for that particular deal.
I'd really appreciate some help here. Thanks in advance for all your help.
---------------------------------------
Here's the script
---------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_tblDeals_tblCompany]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblDeals] DROP CONSTRAINT FK_tblDeals_tblCompany
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_tblDeals_tblContractStatus]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblDeals] DROP CONSTRAINT FK_tblDeals_tblContractStatus
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_tblDeals_tblPhaseType]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblDeals] DROP CONSTRAINT FK_tblDeals_tblPhaseType
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_tblPhase_tblPhaseType]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblPhase] DROP CONSTRAINT FK_tblPhase_tblPhaseType
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_tblProduction_tblDeals]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblProduction] DROP CONSTRAINT FK_tblProduction_tblDeals
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_tblProduction_tblPhase]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblProduction] DROP CONSTRAINT FK_tblProduction_tblPhase
GO
/****** Object: Table [dbo].[tblProduction] Script Date: 11/20/2003 11:30:48 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblProduction]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblProduction]
GO
/****** Object: Table [dbo].[tblDeals] Script Date: 11/20/2003 11:30:48 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblDeals]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblDeals]
GO
/****** Object: Table [dbo].[tblPhase] Script Date: 11/20/2003 11:30:48 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblPhase]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblPhase]
GO
/****** Object: Table [dbo].[tblCompany] Script Date: 11/20/2003 11:30:48 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblCompany]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblCompany]
GO
/****** Object: Table [dbo].[tblContractStatus] Script Date: 11/20/2003 11:30:48 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblContractStatus]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblContractStatus]
GO
/****** Object: Table [dbo].[tblPhaseType] Script Date: 11/20/2003 11:30:48 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblPhaseType]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblPhaseType]
GO
/****** Object: Table [dbo].[tblCompany] Script Date: 11/20/2003 11:30:50 AM ******/
CREATE TABLE [dbo].[tblCompany] (
[CompanyID] [int] IDENTITY (1, 1) NOT NULL ,
[CompanyName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[tblContractStatus] Script Date: 11/20/2003 11:30:50 AM ******/
CREATE TABLE [dbo].[tblContractStatus] (
[StatusID] [tinyint] IDENTITY (1, 1) NOT NULL ,
[Status] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[tblPhaseType] Script Date: 11/20/2003 11:30:51 AM ******/
CREATE TABLE [dbo].[tblPhaseType] (
[PhaseTypeID] [tinyint] IDENTITY (1, 1) NOT NULL ,
[Desription] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[tblDeals] Script Date: 11/20/2003 11:30:51 AM ******/
CREATE TABLE [dbo].[tblDeals] (
[DealID] [int] IDENTITY (1, 1) NOT NULL ,
[CompanyID] [int] NOT NULL ,
[DealDate] [smalldatetime] NOT NULL ,
[PhaseTypeID] [tinyint] NOT NULL ,
[CashAmount] [smallmoney] NOT NULL ,
[StatusID] [tinyint] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[tblPhase] Script Date: 11/20/2003 11:30:52 AM ******/
CREATE TABLE [dbo].[tblPhase] (
[PhaseID] [tinyint] IDENTITY (1, 1) NOT NULL ,
[PhaseTypeID] [tinyint] NOT NULL ,
[PhaseDescription] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[PhasePercentage] [float] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[tblProduction] Script Date: 11/20/2003 11:30:52 AM ******/
CREATE TABLE [dbo].[tblProduction] (
[TransactionID] [int] IDENTITY (1, 1) NOT NULL ,
[DealID] [int] NOT NULL ,
[PhaseID] [tinyint] NOT NULL ,
[TransactionTimeStamp] [smalldatetime] NOT NULL ,
[Comments] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblCompany] WITH NOCHECK ADD
CONSTRAINT [PK_tblCompany] PRIMARY KEY CLUSTERED
(
[CompanyID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblContractStatus] WITH NOCHECK ADD
CONSTRAINT [PK_tblContractStatus] PRIMARY KEY CLUSTERED
(
[StatusID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblPhaseType] WITH NOCHECK ADD
CONSTRAINT [PK_tblPhaseType] PRIMARY KEY CLUSTERED
(
[PhaseTypeID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblDeals] WITH NOCHECK ADD
CONSTRAINT [PK_tblDeals] PRIMARY KEY CLUSTERED
(
[DealID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblPhase] WITH NOCHECK ADD
CONSTRAINT [PK_tblPhase] PRIMARY KEY CLUSTERED
(
[PhaseID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblProduction] WITH NOCHECK ADD
CONSTRAINT [PK_tblProduction] PRIMARY KEY CLUSTERED
(
[TransactionID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblDeals] ADD
CONSTRAINT [DF_tblDeals_StatusID] DEFAULT (5) FOR [StatusID]
GO
ALTER TABLE [dbo].[tblProduction] ADD
CONSTRAINT [DF_tblProduction_TransactionTimeStamp] DEFAULT (getdate()) FOR [TransactionTimeStamp]
GO
ALTER TABLE [dbo].[tblDeals] ADD
CONSTRAINT [FK_tblDeals_tblCompany] FOREIGN KEY
(
[CompanyID]
) REFERENCES [dbo].[tblCompany] (
[CompanyID]
),
CONSTRAINT [FK_tblDeals_tblContractStatus] FOREIGN KEY
(
[StatusID]
) REFERENCES [dbo].[tblContractStatus] (
[StatusID]
),
CONSTRAINT [FK_tblDeals_tblPhaseType] FOREIGN KEY
(
[PhaseTypeID]
) REFERENCES [dbo].[tblPhaseType] (
[PhaseTypeID]
)
GO
ALTER TABLE [dbo].[tblPhase] ADD
CONSTRAINT [FK_tblPhase_tblPhaseType] FOREIGN KEY
(
[PhaseTypeID]
) REFERENCES [dbo].[tblPhaseType] (
[PhaseTypeID]
)
GO
ALTER TABLE [dbo].[tblProduction] ADD
CONSTRAINT [FK_tblProduction_tblDeals] FOREIGN KEY
(
[DealID]
) REFERENCES [dbo].[tblDeals] (
[DealID]
),
CONSTRAINT [FK_tblProduction_tblPhase] FOREIGN KEY
(
[PhaseID]
) REFERENCES [dbo].[tblPhase] (
[PhaseID]
)
GO
exec sp_addextendedproperty N'MS_Description', N'Identifier', N'user', N'dbo', N'table', N'tblContractStatus', N'column', N'StatusID'
GO
exec sp_addextendedproperty N'MS_Description', N'Description', N'user', N'dbo', N'table', N'tblContractStatus', N'column', N'Status'
GO
exec sp_addextendedproperty N'MS_Description', N'Determines the type of phase structure this deal will go through', N'user', N'dbo', N'table', N'tblDeals', N'column', N'PhaseTypeID'
GO
exec sp_addextendedproperty N'MS_Description', N'Identifies the current status of deal', N'user', N'dbo', N'table', N'tblDeals', N'column', N'StatusID'
GO
exec sp_addextendedproperty N'MS_Description', N'Determines the percentage value of the phase', N'user', N'dbo', N'table', N'tblPhase', N'column', N'PhasePercentage'
GO
exec sp_addextendedproperty N'MS_Description', null, N'user', N'dbo', N'table', N'tblProduction', N'column', N'TransactionTimeStamp'
GO
---------------------------------------
And here's some data
---------------------------------------
INSERT INTO [tblPhaseType] ([Desription])VALUES('TV Commercial - 4 Phases')
INSERT INTO [tblPhaseType] ([Desription])VALUES('Full Campaign - 6 Phases')
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(1,'Customer Info',1.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(1,'Write script',2.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(1,'Shoot',3.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(1,'Edit commercial',2.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(2,'Customer info',1.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(2,'Write script',1.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(2,'Design print ad',1.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(2,'Shoot',1.500000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(2,'Edit',2.000000000000000e-001)
INSERT INTO [tblPhase] ([PhaseTypeID],[PhaseDescription],[PhasePercentage])VALUES(2,'Publish',2.000000000000000e-001)
INSERT INTO [tblContractStatus] ([Status])VALUES('Completed')
INSERT INTO [tblContractStatus] ([Status])VALUES('Hold')
INSERT INTO [tblContractStatus] ([Status])VALUES('Collections')
INSERT INTO [tblContractStatus] ([Status])VALUES('Legal')
INSERT INTO [tblContractStatus] ([Status])VALUES('In Progress')
INSERT INTO [tblCompany] ([CompanyName])VALUES('Johnny''s Remodeling')
INSERT INTO [tblCompany] ([CompanyName])VALUES('Perfect Cut Lawncare')
INSERT INTO [tblCompany] ([CompanyName])VALUES('Useless Ideas Unlimited')
INSERT INTO [tblCompany] ([CompanyName])VALUES('Try-It-Again, Inc.')
INSERT INTO [tblDeals] ([CompanyID],[DealDate],[PhaseTypeID],[CashAmount],[StatusID])VALUES(1,'Aug 5 2003 12:00:00:000AM',1,120.0000,5)
INSERT INTO [tblDeals] ([CompanyID],[DealDate],[PhaseTypeID],[CashAmount],[StatusID])VALUES(2,'Sep 9 2003 12:00:00:000AM',2,150.0000,5)
INSERT INTO [tblDeals] ([CompanyID],[DealDate],[PhaseTypeID],[CashAmount],[StatusID])VALUES(3,'Sep 10 2003 12:00:00:000AM',2,130.0000,5)
INSERT INTO [tblDeals] ([CompanyID],[DealDate],[PhaseTypeID],[CashAmount],[StatusID])VALUES(4,'Nov 20 2003 12:00:00:000AM',1,190.0000,5)
INSERT INTO [tblProduction] ([DealID],[PhaseID],[TransactionTimeStamp],[Comments])VALUES(1,1,'Nov 10 2003 10:23:00:000AM','Received company logo')
INSERT INTO [tblProduction] ([DealID],[PhaseID],[TransactionTimeStamp],[Comments])VALUES(1,2,'Nov 10 2003 10:23:00:000AM','Finished writing script')
INSERT INTO [tblProduction] ([DealID],[PhaseID],[TransactionTimeStamp],[Comments])VALUES(2,5,'Nov 10 2003 10:23:00:000AM','Just received company info')
INSERT INTO [tblProduction] ([DealID],[PhaseID],[TransactionTimeStamp],[Comments])VALUES(2,7,'Nov 10 2003 10:24:00:000AM','Finished designing ad copy')
INSERT INTO [tblProduction] ([DealID],[PhaseID],[TransactionTimeStamp],[Comments])VALUES(1,3,'Nov 20 2003 11:29:00:000AM','Did more work')
INSERT INTO [tblProduction] ([DealID],[PhaseID],[TransactionTimeStamp],[Comments])VALUES(1,4,'Nov 20 2003 11:29:00:000AM','Finally finished the job')
View 3 Replies
View Related
Jun 16, 2004
i have a query and i would like to write the contents of the dataset out directly to a file and not bother with creating another temp table and then exporting it with a command with a dts to a csv file.
it is a type of reporting that i am trying to do
but i just need to export the raw data i retreive from the query
View 3 Replies
View Related
Oct 25, 1999
Is it possible to do the following without cursors or creating an identity column:
I have a table from legacy data with ~ 1 million records. I need to insert this into the new table which has a unique varchar(11) key. For the new system this key is generated by calling a SP that returns the next key in sequence. To put the legacy data records in the same table I want to first create a new column at end of legacy data table and populate this using SQL without going thru using cursor and calling the SP for each and every record to get a unique varchar(11) key.
In short here is what I want:
Field1 Field2 varchar(11)key
------ ------ -----------
jsdhf dsf99 1LEG
878jh whjhj 2LEG
8728jh whjhj 3LEG
8578jh whjhj 4LEG
3878jh whjhj 5LEG
6878jh whjhj 6LEG
8508jh whjhj 7LEG
...
...
...
4878jh whjhj 1000000LEG
How do I generate this key using an SQL stmt?
Thanks in advance,
Nishi
View 4 Replies
View Related
Oct 18, 1999
I have a table that has records that have multiple entries with only a slight varitation to accomodate client needs. I want to filter out the duplicates and call only one record row. How can I do this type of thing and make it work; example - SELECT * FROM clients WHERE client_id DISTINCT
I know that is not correct but that is what I need. I need to get all the columns but only one record for each client using the client_id field as the source of information.????
View 2 Replies
View Related
Apr 5, 2006
I have table Products
I have coloumn like ProductName:
ProductName Having two values like Colgate and pepsi
I want to change these coloumn values in the result set
Please write a query
Hi here is clear question?
Table Name is Products
in that One coloumn name is
ProductsName:
and the values for productsName are
colgate
pepsi
the result set should be like following way
ProductsName:
Mike
Johnson
so here I am replacing value Mike instead of colgate
and Johnson instead of pepsi
View 1 Replies
View Related
Apr 14, 2006
Please help with writing query
I have 2 tables:
Table1:
IDDescription
1name1
2name2
3name3...
Table2:
SiDID
1231
4562
789myname
852yourname
if description exisits in table1 get description from table1 in
all other cases get ID from table2
View 5 Replies
View Related
Apr 19, 2006
please help me write a query:
I have a user function dbo.udf_Valid which is return true or false
(@SID ,@PType,@Group,@Date)
Table 1 with this info:
SID PType Group
12 12 123
45 1 456
Table2 with this info:
PType PType2
12 13
12 45
12 8
1 8
1 9
when I pass the data from table1 to the function I am Okay.
The complexity starts when table2 is involved.
I need to pass PType2 to the function if Ptype is exists in table1.
If function returns true for one of the PType2 return true in all other cases false.
View 3 Replies
View Related
Aug 8, 2005
I need assistance on writing a particular query:
I need to be able to filter out duplicates that have different values in a particular field.
For example, I have a table that contains the following:
Code:
WBS1 WBS2 WBS3 Amount Section
123 13 00 475 F
123 13 00 0 L
123 21 01 125 C
123 24 03 50 L
I need to filter out the first two lines because they have the same values for the first three columns but the last column under 'Section' has different values.
Can someone help me?
Thanks
View 2 Replies
View Related