Writing Smart SQL

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


ADVERTISEMENT

Who's Smart Enough To Figure This Out?

Mar 9, 2004

Hello All,

I've been trying to get a range of values out of my SQL Server 2000 db without sucess. The field in question has the data type of char(8) and looks like this:

House_numbr_pub (leading spaces in front of each value)
140A
140
141
142
143
144
145
146
147
148
149
150
151
.
.
.
14500
.
.
.

Does anyone know how write a sql statement that will return 140-150, but excluding the ' 14500' and 100-1000. I tried the following where clause to return a range between 100-1000.

WHERE (cook.STREET_PUB LIKE 'lincoln%') AND (LEN(LTRIM(cook.HOUSE_NUMBR_PUB)) BETWEEN 3 AND 4) AND (
(LTRIM(cook.HOUSE_NUMBR_PUB) >= '100') and (LTRIM(cook.HOUSE_NUMBR_PUB) <= '1000') )

This where clause only return two records (100 and 1000). I want it to return 100-1000.

I also tried the following where clause:

WHERE LTrim(cook.HOUSE_NUMBR_PUB) like '1[45][0-9]'
OR
LTrim(cook.HOUSE_NUMBR_PUB) like '1[45][0-9]'

However, building this on the fly with .net will take some effort if someone is trying to search range 1-10000000.


Please Help,

James

View 3 Replies View Related

Smart Trigger...

Oct 10, 2007

Hello forum.
I have a problem that is kill me.
Initial dates: a table (Tbl_1) to collect dates from users (within form in VB), a view (View_1) to compute some columns (is a part from business€™ logic) and a table (Tbl_2) designated for a trigger.
I will try to resume the contents of above table€¦
create table Tbl_1
(
id int not null,
code varchar(10) null,
TBO int not null, -- (Time between Overhauling)..hours (life cycle)
T_Hrs_AtLastOvh int null, -- total running hours from last overhauling
TRH int null, -- total running hours (the life of equipment)
)
GO
Create view View_1
as
select code, [TBO]-([TRH]-[T_Hrs_AtLastOvh])as HrsTo_NextOvh
from Tbl_1
GO
create table Tbl_2
(
id int not null,
code varchar(10) null,
Start_dt smalldatetime,
Stop_dt smalldatetime,
)
GO
--drop table Tbl_1
--drop view View_1
--drop table Tbl_2

Let to insert some dates into Tbl_1:

Insert into Tbl_1
select 1,'cod1',2000,2500,3000
union all
select 2,'cod2',3000,4000,7000
union all
select 3,'cod3',1000,2000,2000
union all
select 4,'cod4',1500,3000,3000
GO
The result of View_1 is in Fig.1:






Fig.1






cod1

1500


cod2

0


cod3

0


cod4

2500




cod1

1500


cod2

3000


cod3

0


cod4

2500







Fig.2





The operator perform requested job for the equipment and the life cycle starts counting again. Suppose to have:

Update Tbl_1 set T_Hrs_AtLastOvh=7000 where id=2
GO
The result of View_1 is Fig.2.
I wish to insert (within trigger) into table Tbl_2 all codes that have [HrsTo_NextOvh]=0 from View_1 and automatic to record the date when the record is done with a propertie like €™starting job€™.
After the operator executed the job, he will update the Tbl_1 (the result is in Fig.2) and the trigger has to record this process with the propertie like €˜completed job€™.
Depending by the time between overhauling and the operating hours of equipments, this task happens more or less often.
My intentions are to record the time requested to executed a job and to make a history of events.

Any suggestion to solve my problem is full apreciated.

View 6 Replies View Related

Smart Aggregation

Jan 1, 2007

I'm having problems implementing the following in reporting services 2005.

My hierarchy looks like this (just to illustrate the problem...):

University->Student->Exam

My query returns the following fields:

University,Student,StudentPayment,ExamName,ExamScore

I need to create a report that will show the hierarchy and to smartly aggregate the StudentPayment to both the Student and the University levels.

The problem is that the StudentPayment field is being multiplied by the number of exams in the upper level aggregation.

If only I could set the granularity level of the StudentPayment measurement...

Note that I don't have access to the query, so I can't change anything on that front.

Thanks,

Efi

View 6 Replies View Related

REAL CHALLENGE For The Smart One

May 8, 2002

Hi,
tell me please how I can trace the modification on the table such as "insert" record into one and syncronize mirror table at the same time once the insert has happend, BUT - no indexes no trace jobs, no any modification or objects on the master table... ha?

View 5 Replies View Related

Thoughts About The Smart Way To A Task

Jul 20, 2005

I'm still a database newbie so I would like to solicit thoughts aboutthe smartest way to do something in sqlserver.My company has a web application that we customize for each client.We can do this because everything is database driven. We havedatabase tables that contain our HTML and database tables as well assome standard tables for each database. We have an in house app thatlets us tweak both of these things and creates a new web site anddatabase tailored to each project.Each of these sites has a table that stores a schedule are clientsuse.The records in this schedule table change when information in othercustom generated tables change.My company currently uses a legacy foxpro app to update the scheduletable.The foxpro app contacts sqlserver, reads a table with a list of tablesand scheduling information to check, checks each of those items andupdates the schedule table.I would like to lose the foxpro app.At first thought.........as a database newbie.......putting triggersin each of the tables to update the schedule when something changesseems the way to go.However, since we change a part of the schema ( we have an app thatgenerates the database tables unique to each client ) for each clientI would like a scheme that would not involve having to create adifferent trigger for each new table.I would also like something that updates in real time. Right now thefoxpro app is executed once a day.I was thinking of making a large stored procedure and putting anidentical call to that procedure in each table.Each table would have the same trigger in it that would get fired whenthe record was altered. It would call the stored procedure withrelevent arguments to update the schedule.Does this sound like a smart way to solve this problem or am I notthinking "database enough"?Any thoughts are welcome.I would like to build a better solutionSteve

View 1 Replies View Related

Win CE 4.2 And Smart Dev Application Question

Apr 18, 2006

I'm a bit stuck with this one... hope someone can help.

I'm trying to develop an application that will run on a pocket PC with Windows CE 4.2

I'm using .Net 2003 and the application is in VB.Net.

I can run the application on the pocket pc fine (ie. form paints, buttons work) , until I need to connect to Sql DB on the server.

When I try to create a connection object (Dim dbconnection As New SqlClient.SqlConnection)

I get an error stating .. "This application (test.exe) requires a newer version of .Net Compact Framework than the one installed on the device" .... "could not load System.Data.SqlClient.SqlConnection from assembly System.Data.SqlClient Version=1.0.5000.0"

The version that it is looking for is. 1.0.5000.0 . The VS2003 is using this version.

I've downloaded the compact framework v1. sp3 , ran all the cabs on the Win CE device ... it looked that it installed fine.... but the problem still exists.

Help Please..

Derek

View 12 Replies View Related

SQL 2012 :: What Is The Concept Of Smart Backup

Jul 6, 2015

what is the concept of smart backup in sql ?

View 1 Replies View Related

SQL SERVER EXPRESS - Vb.net/smart Client

Oct 16, 2006

Hey all... great site!

Here's what I'm going for:

I have an 05 VB.NET windows application that will be used as a smart client for our folks in the field. The windows application includes 05 SQL Server Express. I have included in the Data Sources of my project and attached file going through the wizard Microsoft SQL Server Database File (SqlClient) ='s (myfile.mdf) and then selected all tables, views, stored procedures, and functions... the corresponding myfileDataSet.xsd with the myfile.mdf are now located in the root of the project. I now recompile the project without error and go to the properties section Publish tab... select the Application Files button and myfile.mdf Publish Status is set to Include and the Download Group set to Requried. With this in place I right click on the myfile.mdf from the Soultion Explorer and under the properties section have set the build action to compile and use the copy always setting for the Copy to Output Directory.

My app.config looks like this:

<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="myfile.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="myfile.My.MySettings.ffgscrmConnectionString" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|myfile.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

After the publish is completed on the client machine... install for Windows Installer 3.1, SQL Server Express, and the Windows Application contains no data but everything else works fine.

My problem is that I need to attach the myfile.mdf to the new SQL Server Express instance on the client machine during the installation process so that when the application fires it will be pointed to the above location on the client.

Any ideas... scripts... includes for an ApplicationEvents.vb on how to do this? Thanks a ton... :)

Kind regards,

BillB

Your mind is like a parachute.. It has to be able to open, for it to work.

View 1 Replies View Related

Why Optimizer Is Not Smart? Is Dynamic SQL My Only Option...

Feb 8, 2007

declare @ContactId as integerset @ContactId = 5select *from Person.Contactwhere ContactId = @ContactIdOR @ContactId = -1If you run this in SQL 2005 on the AdventureWorks database,why the logical reads is 561Table 'Contact'. Scan count 1, logical reads 56and not 2 when you run without the second OR condition:declare @ContactId as integerset @ContactId = 5select *from Person.Contactwhere ContactId = @ContactIdHow can i use the same SP and either get one record returnedby passing the ID of the field, or pass a dummy parameter like-1 in order to get ALL the records returned.In this case even when i pass a parameter like ContactID = 5there is still a table scan (clustered index scan in this case)happening for the other OR condition.There's no method to tell SQL to start checking the first conditionwhether or not it is true then if it is false then check the second ORconditon. On the same topic does this mean all OR conditions areALWAYS verified regardless if one of them has already been determinedto be True?Thank you

View 2 Replies View Related

My First Post: Smart SQL Updating Technique..??

Jul 12, 2007

Hello geniuses



First of all I would like to announce that this is my first time I post here.. However, I'm pretty sure that I'm in the best place to ask what I want. To cut the story short, I'm querying SQL database on a remote machine and having the result saved (mapped) to another table on another database on the same remote machine. The thing is the destination table was empty before the query was run the first time. I have been searching for some smart way so that when I modify the source tables that my query is based on, it doesn't affect except the modified rows. In other words, it should be like if the row is already there, do nothing. otherwise, it updates the existig record. else, it's a new record and it's inserted. I think what i need will include some coding for sure, yes? I don't know if i'm clear about the requirement or not though! but I know that you are experts and can direct me. Waiting for your valuable replies.



Sherif Magdi

View 11 Replies View Related

Vs 2008 Smart Device Cab Project And Sqlce 3.5

May 21, 2008

I've created a simple application that uses a SQLCE 3.5 database. When I debug it SQLCE 3.5 is deployed to the emulator. However, I made a "smart device cab project" for my application and copied the cab file to my windows mobile 6 device and it does not deploy SQLCE 3.5. I don't see a way to specify the prerequisites of the "smart device cab project" like you can in a normal setup project. How can I get SQLCE 3.5 to deploy with my application...or even just get it on my device? I've tried installing it on my desktop with the device connected via active sync, but it doesn't install on the device like the compact framework did.

View 3 Replies View Related

Setting Up A Web Synchronized Subscription For A Smart Client

Nov 20, 2005

So in a previous thread I discovered that in order to actually subscribe to any publication, the publisher needs to be a well-known network name, requiring DNS resolution. You can't simply point a SQLExpress instance at an ip addressinstance and have it resolve the communications.

View 5 Replies View Related

Updating Database From A Smart Device Application

May 24, 2007

i m developping a smart device application with vb.net

i m using the following code from:

http://msdn2.microsoft.com/en-us/library/aa454892.aspx

(i still working on the first exercice and i'm following it step by step)

everything is working properly

i was advised to add this code when closing the form1

Try

Me.ContactsBindingSource1.EndEdit()

Me.ContactsTableAdapter1.Update(Me.TestDataSet1.contacts)

MsgBox("Update successful")

Catch ex As Exception

MsgBox("Update failed")

End Try



the problem is:

should this code update the database created with sql server 2005

if yes why isnt it working here

and should the database be replicated on my emulator before it is updated

(in this exercice i do not have a database storerd in the emulator)

plz i urgently need the answer

View 4 Replies View Related

Smart Client - Data Centric - SQL 2K To SSE Local

Jul 4, 2006

Trying to develop a smart client which will have data centric approach for storage of local data. The server is SQL Server 2000 and foot print database is going to SQL Server Express 2005. Is Merge replication a vaiable option. Can somebody guide me on this approach

Is there any other architecture proposed for Smart client arcjitecture where the data tranfer will be in a couple of GBs. Can somebody tell me more about SOA as well

Thanks!

View 4 Replies View Related

Finding Duplicate Entries In A Smart Way - By Comparing First Two Words

Jul 20, 2005

What is the best way to compare two entries in a single table wherethe two fields are "almost" the same?For example, I would like to write a query that would compare thefirst two words in a "company" field. If they are the same, I wouldlike to output them.For example, "20th Century" and "20th Century Fox" in the companyfield would be the same.How do I do this? Do I need to use a cursor? Is it as simple as using"Like?"

View 2 Replies View Related

Smart Device CAB Project Detected Dependencies Not Included?

Jul 5, 2006



Hi

I have created a Smart device application for Windows CE 5.0 device using Visual studio 2005 and i have added the smart cab project to the solution. When I add project out in teh appllication folder, the detected dependencies are not included. Instead dependent files appear with red circle in solution explorer.

My project uses .Net Framework 2.0 and SQL Server mobile 2005 and SQL Server mobile database file and some symbol files

I need included all of them in my cab project and when user clicks on it (in the device) it should install all of them.

Let me know why detected dependencies are not included in the Cab project and how can get all the above mentioned things to be installed along with my program



Regards

Mani

View 4 Replies View Related

Configuring SQL Express During Installation And Attaching Smart Client DB / Silent Install For One Click?

Oct 9, 2006



Hey all,

Cool place! Has anyone deployed SQL Express silently using one click and an attached a smart client DB from within the app ... would love to see some of the best practices or horror stories! Just kidding... :) I'm about to deploy a smart client using SQL Express and could use some tips from someone who has been there.

Thanks in advance,

Bill

View 7 Replies View Related

.Net Framework 3.5 Smart Device Project Deploys The .Net 2.0 SQLClient When Both Vs2008 And Vs2005 Installed

Feb 19, 2008



I have both vs2005 and vs2008 installed. I'm working with a .Net Compact Framework 3.5 Smart Device Project.

If I refrence the System.Data.SqlClient.dll (Version 3.0.3600.0 Runtime v2.0.50727)
C:Program FilesMicrosoft SQL Server Compact Editionv3.5DevicesClientSystem.Data.SqlClient.dll

When I deploy the application I get an error ".Net Compact Framework v2.0 could not be found Please install it and run the setup again"

Studio is :
Deploying 'C:Program FilesMicrosoft Visual Studio 8SmartDevicesSDKSQL ServerClientv2.0wce500ARMV4isql.ppc.wce5.armv4i.CAB'

We tested this on a PC without vs2005 and it seems to work fine.

Any suggestions?


jlj

View 3 Replies View Related

Reporting Server Is Not So Smart As Analysis Server

May 11, 2007

Hi,

I have a fact table with 2 columns value A and value B

In Analysis server I add a calculated column C as A / B

Now my data looks like this

A B C

0 10 0

5 10 0.5



If you add totals in Analysis server you get

5 20 and 0.25 which is correct



If you add totals in Reporting server you get

5 20 and 0.5 which is not correct.



How can I fix this ?



Thanks in advance



Constantijn

View 5 Replies View Related

New To Writing In SQL

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

Writing To SQL Log

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

Writing To SQL

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

Writing SQL Statement

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

Help Writing The SqlConnectionString.

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&quot;;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&quot;;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&quot;;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 (&quot;), but I can't figure out how to write it otherwise.Thank you very much.

View 2 Replies View Related

Need Help On Writing A Query

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

Writing To Database

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

Help Writing Sql Query

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

Sql Query Writing

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

Help Writing SQL Statements

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

Need Help Writing A Trigger

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

Writing Directly To A Csv From Asp.net Vb Behind

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

Help Writing A SQL Script

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







Copyrights 2005-15 www.BigResource.com, All rights reserved