Primary Key Addition

Jan 24, 2001

For an existing table containing data, how would you add a primary key field, that contains a value for each row?

(Under Access I'd just add a new field and set it to type AutoNumber, but you can't do that in SQL Server)

View 1 Replies


ADVERTISEMENT

Addition Of Strings

Aug 28, 2007

How can i make a sum (concatenation) of strings of one column in a table.
for example i have a table like this
field1          field2
1                abc
1                bcd   
2                sdf
2                sdd
I want to get these strings added group by field 1
Thanks

View 5 Replies View Related

Addition Of Char + Int !!!

Jan 15, 2002

Hi Everybody,

I hv executed the following query in the Query Qnalyzer
(Ofcourse I am Using SQL 2000 Enterprise Edition) and Surprisingly
I am getting the Output as follows,

query:-
select '5' + 10

Output:- 15

Can anybody please tell me, why it is happening like this? OR Did I miss any Configuration Parameter in the Server Settings?.

Tks in Advance,
Sam

View 1 Replies View Related

Addition During A Count

May 12, 2008

Hi

Is there anyway to perform a addition on two items in a COUNT query?
For example if i use the followig query:

SELECT
Region
,COUNT(*)
FROM Regions
GROUP BY Regions

It would give me the following results:

Region1 22
Region2 33
Region3 21
Region4 4
Region5 9
Region6 61

However I would want it display the the combined totals Region1 and Region2 together so it would give the figure of 55.

Is this possible?

Thanks

View 6 Replies View Related

Addition Of A Value To A Null Value

Dec 6, 2006

i have the idea that 23+null=null

now following is my case with 2 columns as:

salary bonus
1 null
2 5
3 null

i have to find the total salary(i.e. salary+bonus)

this is how i managed to do it:

select empname,(salary + commission) as 'total salary'
from emp
where commission is not null
union
select empname,salary from emp
where commission is null

now my question is,wht if the case now is different as below:

salary bonus hra
1 null 6
2 5 null
3 null null

now how do i calculate total salary(i.e. salary+bonus+hra)

am a beginner
help appreciated

cheers

View 5 Replies View Related

Addition Of Two Rows

Mar 22, 2007

hi guys,

I have got something like this,

A S D

Bi Ar 23
Bi Ar 12
As Ar 52
As Ar 11
Ap Jo 24

I Have 3 columns. First 2 columns are Text and the third one is Number. I need to see if any duplicate values are there in first 2 columns. If so then i need to add the values of 3 columns and make it one. So the output should look like this,

A S D

Bi Ar 35
As Ar 63
Ap Jo 24

View 15 Replies View Related

Help With Query Nulls And Addition

Mar 16, 2007

Hi I have a query, what I would like to do is create a column that takes the results in two coulms and add them together:
           Col A  Col B Col C
Row1    1          1       2
Row2    2          3       5
Here is the query
declare @t table( player_name varchar(100), BuyIn int, TopUp int, ReBuy int, Winnings int, Events int, Test int)
INSERT INTO @t (player_name, TopUp)
SELECT Player_name, SUM([Top-ups]) AS TOPUPS
FROM (SELECT Event_data.Transaction_type, Players.Player_name, Events.Top_up, Event_data.Transaction_value,
Events.Top_up * Event_data.Transaction_value AS [Top-ups]
FROM Event_data INNER JOIN
Events ON Event_data.Event_id = Events.id INNER JOIN
Players ON Event_data.Player_id = Players.Player_id
WHERE (Event_data.Transaction_type = 2)) AS Topups
GROUP BY player_name
INSERT INTO @t (player_name, ReBuy )
SELECT Player_name, SUM([Re-buys]) AS REBUYS
FROM (SELECT Event_data.Transaction_value, Players.Player_name, Events.Rebuys, Event_data.Transaction_value * Events.Rebuys AS [Re-buys]
FROM Event_data INNER JOIN
Events ON Event_data.Event_id = Events.id INNER JOIN
Players ON Event_data.Player_id = Players.Player_id
WHERE (Event_data.Transaction_type = 3)) AS REBUYS
GROUP BY Player_name
Insert into @t (player_name, BuyIn)
SELECT dbo.Players.Player_name, SUM(dbo.Events.Buy_in) AS BuyIn
FROM dbo.Players INNER JOIN
dbo.Event_data ON dbo.Players.Player_id = dbo.Event_data.Player_id INNER JOIN
dbo.Events ON dbo.Event_data.Event_id = dbo.Events.id
GROUP BY dbo.Players.Player_name, dbo.Event_data.Transaction_type
HAVING (dbo.Event_data.Transaction_type = 1)
ORDER BY SUM(dbo.Events.Buy_in) DESC
 
Insert into @t (player_name, Winnings)
SELECT dbo.Players.Player_name, SUM(dbo.Event_data.Transaction_value) AS Winnings
FROM dbo.Players INNER JOIN
dbo.Event_data ON dbo.Players.Player_id = dbo.Event_data.Player_id
GROUP BY dbo.Players.Player_name, dbo.Event_data.Transaction_type
HAVING (dbo.Event_data.Transaction_type = 1)
insert into @t (player_name, Events)
SELECT dbo.Players.Player_name, COUNT(dbo.Event_data.Place) AS Expr1
FROM dbo.Players INNER JOIN
dbo.Event_data ON dbo.Players.Player_id = dbo.Event_data.Player_id INNER JOIN
dbo.Events ON dbo.Event_data.Event_id = dbo.Events.id
GROUP BY dbo.Players.Player_name
HAVING (NOT (COUNT(dbo.Event_data.Place) IS NULL))
insert into @t (player_name, test)
select player_name, ((TopUp) + (Rebuy)) as Test
from @t
SELECT player_name, min (BuyIn) as BuyIn, min(TopUp) as TopUps, min(ReBuy)as ReBuy, min(Winnings) as Winnings, min(Events) as Events, min(test) as test
FROM @t
GROUP BY player_name
ORDER BY BuyIn DESC
--ORDER BY TOPUPS DESC
 
END
 
 
THis is where I attempt to add the coloms but I get a null result
 
insert into @t (player_name, test)
select player_name, ((TopUp) + (Rebuy)) as Test
from @t
 
any help would be great.

View 5 Replies View Related

Connecting To SQL 5.0 Standard Addition

Jan 7, 2008

I am trying one of the examples from the .NET Framework 2.0 Web-Based Client Development and I'm having a problem authenticating. I'm running everything on my local computer (IIS, SQL 2005 STANDARD ADDITION and Visual Studio). While in Visual Studio (in other words, debug mode) when I run the example, I get the following error:
Cannot open database "pubs" requested by the login. The login failed.Login failed for user 'DPJ-6E95AFFA416ASPNET'.
 This could be more of a SQL question that a ASP.NET question, but I'm not sure. I'm running under the local administrator account, but this seems to indicate that ASP is using it's own credentials to access SQL. This is my first time using these tools, and I'm guessing this is a fairly well know issue.
 I was looking for a "User Admin" function in SQL and could not find it, so I'm a bit lost here.
Can anyone help please.
 Thanks

View 6 Replies View Related

Asp:Checkbox Addition To Database

May 12, 2008

I have a form set-up and am trying to add multiple items in my checkbox to the database; however, the only thing added to the database is the first item checked.  Here is the code and any help will be greatly appreciated.  Thank you!:<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConConnectionString %>" InsertCommand="INSERT INTO Consultations(FullName, Email, Business, BusinessInfo, Services, Comments) VALUES (@FullName, @Email, @Business, @BusinessInfo, @Services, @Comments)"
SelectCommand="SELECT Consultations.* FROM Consultations">
<InsertParameters>
<asp:ControlParameter Name="FullName" Type="String" ControlId="fullname" PropertyName="Text" />
<asp:ControlParameter Name="Email" Type="String" ControlId="emailTextBox" PropertyName="Text" />
<asp:ControlParameter Name="Business" Type="String" ControlId="bisDropDownList" PropertyName="SelectedValue" />
<asp:ControlParameter Name="BusinessInfo" Type="String" ControlId="businessTextBox" PropertyName="Text" />
<asp:ControlParameter Name="Services" Type="String" ControlID="checkboxlist" PropertyName="SelectedValue" />
<asp:ControlParameter Name="Comments" Type="String" ControlID="commentsTextBox" PropertyName="Text" />
 
</InsertParameters>
</asp:SqlDataSource>

View 3 Replies View Related

License Connection Addition

Nov 14, 2000

I need to up my license limit on a SQL box from 1 to 2 user connections allowed. Where do I do this?

View 1 Replies View Related

Addition Of A Number To An INT Column

Dec 1, 2007

Hi,

I have several INT columns in a table that I need to update.

For example, in column 'aa' I need to add 2 to all of the values in that column.

I'm using Query Analyzer - what update statement should I write?

View 3 Replies View Related

Doing Addition In Update Query Using Value From Txtbox

Jun 21, 2008

@quantity is the number that the user has input in the txtbox. I want to use this value to ADD together with the current quantity value in the shopcartitem table. I do not know how, my current query only replaces the old quantity with the new .. can someone help me? strSql = "UPDATE ShopCartItem sci SET sci.Quantity" & _
"WHERE sci.ProductID=@ProductID AND sci.ShopCartID=@ShopCartID"Dim cmd2 As New SqlCommand(strSql, conn)
cmd2.Parameters.AddWithValue("@Quantity", quantity)cmd2.Parameters.AddWithValue("@ProductID", productId)
cmd2.Parameters.AddWithValue("@ShopCartID", ShopCartID)
 

View 1 Replies View Related

Alert For Automatic Addition Of Record

Dec 10, 2013

I've two databases with different structures, i want to add a record with it's data from the first database into the second database in the place i define, this action must happen automatically as soon as the record is created in the first database.

View 1 Replies View Related

Is There A Way To Perform An Addition To The Value Of A Report Parameter?

Nov 8, 2007



Hi,
is there a way to perform an addition to the value of a report parameter?
so like Param Value + 1 = 6
where Param Value would be 5?


View 11 Replies View Related

Testing Using SQL Server 05 Developer Addition

Feb 2, 2008

Are there any differences between the Developer Addition and Enterprise Addition of 64 Bit SQL Server 05 that would prevent me from testing full capabilities of my production Enterprise Addition in a QA environment utilizing Developer Addition? Any known restrictions on number of DB connections, memory, CPUs etc??

View 4 Replies View Related

Set Amounts To Zero In Addition If No Records Found

May 9, 2006

How can I check for Null for the amounts if no records are returned in either select.  Basically it errors out if one or both of the Amounts return no records.  I need to do some sort of IF statement to set one of the amounts or both amounts to zero in those cases so it doesn't error out on me

   SELECT (Coalesce(pd1_Amount, 0) + Coalesce(PD2_Amount, 0)) as Amount
   FROM    
     (

     SELECT pd.Amount as pd1_Amount
          FROM Master m (NOLOCK)
          LEFT JOIN dbo.pdc pd ON pd.number = m.number
          INNER JOIN dbo.Customer c ON c.Customer = m.Customer

          WHERE     pd.Active = 1
                    AND pd.Entered BETWEEN DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate) + 1, @FirstDayMonthDate) AND DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate), DATEADD(MONTH, 1, @FirstDayMonthDate))
     AND pd.Entered <> '1900-01-01 00:00:00.000'
                    AND pd.Deposit BETWEEN DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate) + 1, @FirstDayMonthDate) AND DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate), DATEADD(MONTH, 1, @FirstDayMonthDate))
                    --AND pd.Deposit IS NOT NULL    
                    --AND pd.OnHold IS NULL
                    AND c.customer <> '9999999'
          
          UNION

          SELECT   pdd.Amount as PD2_Amount
          FROM Master m (NOLOCK)
          LEFT JOIN dbo.pdcdeleted pdd ON pdd.number = m.number
          INNER JOIN dbo.Customer c ON c.Customer = m.Customer

          WHERE     pdd.Entered BETWEEN DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate) + 1, @FirstDayMonthDate) AND DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate), DATEADD(MONTH, 1, @FirstDayMonthDate))
              AND pdd.Entered <> '1900-01-01 00:00:00.000'
                    AND pdd.Deposit BETWEEN DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate) + 1, @FirstDayMonthDate) AND DATEADD(DAY, -DATEPART(DAY, @FirstDayMonthDate), DATEADD(MONTH, 1, @FirstDayMonthDate))
                    --AND pdd.Deposit IS NOT NULL    
                    --AND pdd.OnHold IS NULL
                    AND c.customer <> '9999999'
) as PDC_Main

View 3 Replies View Related

Copy Data From One Table To Another With Addition Insert Value

Sep 6, 2007

Hi,
 I was wondering if you can help.
In my vb.net form I am running a query to insert data from one database table to another. 
However what I need to do is to be able is to add the id of a record I have just created to this insert into sql command.
I have managed to use @@ identity to get the id of my first sql insert statement
but I am wondering how I can use it in the second insert into and select statement. At the moment my sql statement just copies exactly what is in the select statement. I can't figure out how to add the @@identity value to my second sql statement. 
My second sql statement is a follows:
sql2 = "INSERT INTO ProjectDeliveData(ProjId,ProjDeliveId,RoleId,MeasurementId,ProjDeliveValue, ProjDeliveComments,ProjDeliveYear,FinDataTypeId, FinFileId, ProjDeliveMonthFrom, ResourceId,ProjDeliveDateAdded)" & " select ProjId,ProjDeliveId,RoleId,MeasurementId,ProjDeliveValue, ProjDeliveComments,ProjDeliveYear,FinDataTypeId, FinFileId, ProjDeliveMonthFrom, ResourceId,ProjDeliveDateAdded from ProjectDeliveData where FinFileId=" & strActualFileId
I hope you can help
Cheers
Mark :)
 

View 7 Replies View Related

Addition Of Columns In Table, Which One Use In Merge Replication.

Nov 29, 2004

Dear all participants,

I manage complete online system for two locations, connected via dialup lease line. I have to used merge replication for the same data should be at both locations. It is working fine, I don’t like disturbe it but current requirement is addition of two column in one table which one as also use in merge replication.

How I can add aforesaid columns in table x, column name c1 numeric , c2 character?

What is impact on replication?

Let me know step by step.

Thanks in advance.

Thanks R.Mall

View 1 Replies View Related

Addition Of Article In Runnung MERGE Replication

Jan 22, 2005

Can any help me addition of article in runnning merge replication in MSSQL SERVER 2000 with SP3.

Any step by step help is realy great for me.

Thanks

R.Mall

View 1 Replies View Related

How Does Addition Of Two Datetime Data Types Work ?

Apr 3, 2004

SQL Server allows addition of two "datetime" values. For example let d1='April 10,2004' and d2='April 11, 2004'. Now when I execute d1+d2 I get 2108-07-20 00:00:00.000. On what logic is this calculation done.

I am actually looking to derive the same result in Oracle. Hence wanting to know the funda behind this.

many thanks.

View 2 Replies View Related

SQL 2012 :: How To Test A Proposed Index Addition

Sep 29, 2015

My goal is to be able to include test information in the change request that will make the operations manager confident that the change can proceed. Right now all I can think of is to add the index in dev and staging and compare some before and after stats. But I am concerned that an index change might also affect other operations besides SELECTs - such as updates, transactions, or scheduled jobs.

[URL]

View 0 Replies View Related

Reporting Services :: Losing History When Existing Report Is Redeployed With New Parameter Addition

May 29, 2015

We are using SSRS 2012. Before we were with 2005. Both the versions have the problem. When a change made to parameters (like adding additional parameter to existing report or changing default value of parameter) using visual studio on developers machine and re-deploy to server, additional parameter or changes to parameter is not showing up. So, we are first deleting the report from server and then re-deploying. This works fine. But we realized that we are losing history of the report (like data related to this report run from execution log). We need the history of report. It is very important to top management to see the details.When I searched in forums, users say that it still exist in 2012 and 2014 and every one talks about deleting and re-deploying report. I would like to know if there is any other alternate route to redeploy additional parameter and not lose history.

View 6 Replies View Related

SSIS Called From Agent Job Not Calling New Child SSIS Package Addition

Oct 29, 2007

I have an SSIS package (TransAgentMaster) that I recently modified to include a call to a child package via the file system. The child package creates a text file. When I run the package in dev studio then the child package/text file is produced.

I then imported the TransAgentMaster as a stored packagesfilesystem package into SQL SSIS and executed the package. The child package produced the text file.

I then ran the SQL Server Agent to see if the child package would work and it did not generate the text file. Thus after updating a SSIS package importing the package into SSIS the job that calls the package will not call the child package. Please not that the TransAgentMaster package calls 7 children packages €¦ just not my new one.


Any thoughts why the agent will not run the child newly crated childe package?

View 3 Replies View Related

Convert Composite Primary Key Into Simple Primary Key

Jan 11, 2007

Uma writes "Hi Dear,
I have A Table , Which Primary key consists of 6 columns.
total Number of Columns in the table are 16. Now i Want to Convert my Composite Primary key into simple primary key.there are already 2200 records in the table and no referential integrity (foriegn key ) exist.

may i convert Composite Primary key into simple primary key in thr table like this.



Thanks,
Uma"

View 1 Replies View Related

Adding Primary Key To A Table Which Has Already A Primary Key

Aug 28, 2002

Hi all,
Can anyone suggest me on Adding primary key to a table which has already a primary key.

Thanks,
Jeyam

View 9 Replies View Related

Auto Incremented Integer Primary Keys Vs Varchar Primary Keys

Aug 13, 2007

Hi,

I have recently been looking at a database and wondered if anyone can tell me what the advantages are supporting a unique collumn, which can essentially be seen as the primary key, with an identity seed integer primary key.

For example:

id [unique integer auto incremented primary key - not null],
ClientCode [unique index varchar - not null],
name [varchar null],
surname [varchar null]

isn't it just better to use ClientCode as the primary key straight of because when one references the above table, it can be done easier with the ClientCode since you dont have to do a lookup on the ClientCode everytime.

Regards
Mike

View 7 Replies View Related

SQL Server 2008 :: Change Primary Key Non-clustered To Primary Key Clustered

Feb 4, 2015

We have a table, which has one clustered index and one non clustered index(primary key). I want to drop the existing clustered index and make the primary key as clustered. Is there any easy way to do that. Will Drop_Existing support on this matter?

View 2 Replies View Related

4 Key Primary Key Vs 1 Key 'artificial' Primary Key

Jan 28, 2004

Hi all

I have the following table

CREATE TABLE [dbo].[property_instance] (
[property_instance_id] [int] IDENTITY (1, 1) NOT NULL ,
[application_id] [int] NOT NULL ,
[owner_id] [nvarchar] (100) NOT NULL ,
[property_id] [int] NOT NULL ,
[owner_type_id] [int] NOT NULL ,
[property_value] [ntext] NOT NULL ,
[date_created] [datetime] NOT NULL ,
[date_modified] [datetime] NULL
)

I have created an 'artificial' primary key, property_instance_id. The 'true' primary key is application_id, owner_id, property_id and owner_type_id

In this specific instance
- property_instance_id will never be a foreign key into another table
- queries will generally use application_id, owner_id, property_id and owner_type_id in the WHERE clause when searching for a particular row
- Once inserted, none of the application_id, owner_id, property_id or owner_type_id columns will ever be modified

I generally like to create artificial primary keys whenever the primary key would otherwise consist of more than 2 columns.

What do people think the advantages and disadvantages of each technique are? Do you recommend I go with the existing model, or should I remove the artificial primary key column and just go with a 4 column primary key for this table?

Thanks Matt

View 5 Replies View Related

Primary Key

Aug 31, 2006

Hello all,I'm taking over a project from another developer and i've run into a bit of a problem. This developer had a bad habit of not using primary keys when designing various databases used by his programs. So now i've got approx 1000 tables all of which do not have primary keys assigned. Does anyone know of a tsql script that i can run that will loop through each table and add a primary key field?Thanks in advance?Richard M. 

View 2 Replies View Related

Primary Key

Aug 16, 2007

I have a Department Table.
Can any one tell me its Primary Key.
I have the order
AutoNumber, D + AutoNumber, Code,
Can you help me regarding this.
Because some people never like to use AutoNumber.
That's why I am confused.

View 3 Replies View Related

Primary Key

Nov 8, 2007

Hi..



I'm going to build database of university, but I have problem with primaru key,



This is the situation:

there are many faculities and each one has many departments,

each department has many courses,

each course has many sections..



The problem:

I want to make those fields in the same table and make the primary key generate from other fields,

(i.e)

I want the faculity be integer from 4 digit "Example the first faculity start with 1000 the second 2000 and so on" and the the department of each faculity will generate its value from the faculity number+interger number from 3digit "Example the department of the first faculity start with 1100 and the second on will be 1200 and so on "

the same thing will repeate for courses and sections so the sectionsID will be the primary key.



Do you know hoew this idea can be implement by SQL server 2005?

Please help me as soon as possible.

View 13 Replies View Related

Primary ID = BC

Mar 23, 2005

A column will be Primary Key. Others are B and C. I want A will contain B and C. I mean B data is X, C data is Y, A will be XY. How can i do this? Can i set in MSSQL or need ASP.NET?

View 1 Replies View Related

Primary Key

Dec 1, 1998

Heya,

I'm trying to setup a Primary Key on a SQL 6.5 database.

Is there a way to do this? When I hit advanced, it asks for me to select a field for the primary key, but it doesnt list fields to selct from, and I cant type it in.

Thanks for your help,

View 3 Replies View Related







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