Newbie Needs Help On Joining Query

Oct 11, 2007

Hi All,

First off sorry for my complete lack of experience with SQL, but I've just started a new position which involved learning SQL. I'm currently looking for a course but in the mean time I just have to try and fumble by doing basic things.

I'm trying to write my first basic select / join statement, and I just can't seem to get it working.

Any help would really be appreciated. It's T-SQL we use btw.

Thanks :)



USE MLSDHeat
GO

select * from dbo.CallLog
where callstatus between 'open'and 'pending'
right outer join dbo.Asgnmnt
on callid = callid
order by callid



--the above returns error Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'right'.

View 2 Replies


ADVERTISEMENT

Newbie Needing Help With Joining 2 Fields

Feb 12, 2007

I have a sql 2005 dev ed running an application developed in vs.net 2005 C# I have several gridviews which have a field call first name and a field called lastname I need to put both the firstname and lastname in the same cell or colum row. I do not now how to join these. Can some one help me with a SQL query string that will do this for me.

View 2 Replies View Related

Joining 3 Tables On The Query

Mar 15, 2007

I know how to join 2 tables, but I have a third I need to insert. For some reason, this doesn't work:


Code:

$rows = ff_select(
"select ".
"u.email as email, ".
"c.user_id as user_id, ".
"u.name as name, ".
"r.age as age ".
"from #__comprofiler as c ".
"left join #__users as u on c.user_id = u.id ".
"left join #__rnr_contest as r on c.user_id = r.userid ".
"where (r.age != chicken) and (r.age != nystrip) and (r.age != regrets) and (u.block = 0) and (c.cb_contactmethod LIKE '%Email%') and (u.usertype != 'Super Administrator') and (u.email != 'please@change.com') and (u.username != 'guest') and (u.username != 'piedmont') ".
"order by email"



anyone see why? It tells me that "chicken" is not a column which is weird because I don't think it's listed as a column in my query... is it?

View 3 Replies View Related

Joining Function - Query

Feb 27, 2008

CREATE FUNCTION dbo.fn_copdmailinglist(@list_ varchar(60))
RETURNS @copdmailinglist TABLE
(
list_ varchar(60) ,
title_ varchar(255) ,
desc_ varchar(255),
message_id int ,
txt varchar(255) ,
cnt int ,
cnt_txt varchar(255)
)

--Returns a result set that lists all the copds
AS
BEGIN
WITH ListManager.dbo.[List Copd](list_ , title_ , message_id , txt , cnt , cnt_txt ) AS
(select @list_ , gmc.name_, osc.message_id , txt , cnt , cnt_txt from ListManager.dbo.[Open statisticscopd]('') osc
left outer join ListManager.dbo.get_mailingidcopd_('') gmc
on gmc.name_ = osc.title_
where list_ = @list_
)

-- copy the required columns to the result of the function
INSERT @copdmailinglist
SELECT list_ , title_ , message_id , txt , cnt , cnt_txt
FROM ListManager.dbo.[List Copd]
RETURN
END
GO

i m getting error that Incorrect syntax near the keyword 'WITH'.

can anyone tell me how to join functions in sql?

thanks.

View 4 Replies View Related

Query Help Joining 2 Tables

Jul 23, 2005

Select LOCGeneralHave.LSCH, LOCSubClassHave.LSCH from LOCGeneralHave ,LOCSubClassHave Where (LOCGeneralHave.LCNT <> '0' andLOCSubClassHave.LCNT = '0')This query seems to be ignoring the 'and' part of the clause.Basically I want select from table1, table2 where LCNT in table1 is not0 andLCNT in table2 is 0.I have verified the LCNT's numbersThis query returns 2 columns with 1700 rowsIt needs to only find a few rows.What am I missing, any ideas, thanks for any help.

View 4 Replies View Related

Joining Two Fields In A Query

Apr 26, 2006



I am trying to join two fields in a query in SQL 2000. For example.

Update myTable SET field_1 = @field_1_value , field_2 = @field_2_value, field_3 = @field_1_value + ' x ' + field_2_value



Is this even possible.

I want the user to input values for fields 1 and 2, then in the background combine the two and insert that value in field 3.



Thanks in advance,

Scotty_C

View 7 Replies View Related

SQL-Query Mindbugger Joining A 2 Views

Oct 23, 2006

Ok, What I want to achieve is plain stuff, I want to join 2 views on a common key.It all works well with the SQL2000 Query Analyzer, but not trough ADO.NET or should I say my webapplication.With that I mean that my query return rows when executed from SQL2000 Query Analyzer, But not when used in my application or Executed from the Visual Studio Server Explorer.I have struggled with this one for several hours, I cant get this one right.So lets bring in the one who actually know what his doing View1: 1 select
2 cast((PS.RabattProsent/100.00)*PS.Pris AS decimal(11,2)) AS Rabatt
3 ,cast((PS.MVAProsent/100.00)*PS.Pris AS decimal(11,2)) AS MVA
4 ,cast(PS.Antall * ((PS.Pris*(100-PS.RabattProsent))/100)*((PS.MvaProsent/100.00)+1) AS decimal(11,2)) AS Belop
5 ,PS.*
6 ,K.Kunde_ID
7 FROM
8 tbl_ProduktSalg AS PS
9 INNER JOIN
10 tbl_Ordre AS O
11 ON
12 O.Ordre_ID = PS.Ordre_ID
13 INNER JOIN
14 tbl_Kunde AS K
15 ON
16 K.Kunde_ID = O.Kunde_IDView2: 1 SELECT
2 PS.Ordre_ID
3 ,SUM(cast((PS.RabattProsent/100.00)*PS.Pris AS decimal(11,2))) AS TotalRabatt
4 ,SUM(cast(PS.Antall * ((PS.Pris*(100-PS.RabattProsent))/100)*((PS.MvaProsent/100.00)+1) AS decimal(11,2))) AS TotalBelop
5 ,SUM(PS.Pris) AS TotalPris
6 ,SUM(cast((PS.MVAProsent/100.00)*PS.Pris AS decimal(11,2))) AS TotalMVA
7 FROM
8 tbl_ProduktSalg AS PS
9 GROUP BY
10 PS.Ordre_ID
   MyQuery/SPRC: 1 create procedure %PROC% (@Kunde_ID int, @Ordre_ID int)
2 as
3 begin
4 SELECT
5 v_PSD.*
6 ,v_OTS.TotalRabatt
7 ,v_OTS.TotalBelop
8 ,v_OTS.TotalPris
9 ,v_OTS.TotalMVA
10 FROM
11 v_ProduktSalgDetaljer AS v_PSD
12 INNER JOIN
13 v_OrdreTotalSum AS v_OTS
14 ON
15 v_OTS.Ordre_ID = v_PSD.Ordre_ID
16 WHERE
17 v_PSD.Kunde_ID = @Kunde_ID
18 AND
19 v_PSD.Ordre_ID = @Ordre_ID
20
21 end
22
  

View 3 Replies View Related

Joining Views && Query Performance

May 1, 2006

Over the years I've read and experienced where joining more then 5 tables can lead to performance problems. This number can vary based upon the amount of data in each table, if and how indexes are used and the complexity of the query, but 5 has always been a good rule of thumb. Unfortunately I do not know what rule to apply in regards to joing views.

A developer has experienced timeout problems periodically when opening a view in EM or when running the code which makes-up the view. I decided to look at the view and noticed it references tables and views, which reference more views, which in turn reference other views. In all the initial view references 5 tables and 8 views directly and indirectly, with some of the views containing function calls. What are your thoughts on how many views and tables are too many when it comes to joins and query performance.

Thanks, Dave

View 6 Replies View Related

Joining Four Tables In A Single Query

Mar 19, 2015

I have four tables:

a, b, c and d

table a is related to table b by a foreign key. table b is related to c and so on.

I used the sql statement below to join the tables:

$result = mysql_query("SELECT a.colum1, a.column2,
b.column, c.column, d.column FROM a

JOIN b ON a.pkey = b.foreign key
JOIN c ON b.pkey = c.fkey
JOIN d ON c.pkey = d.fkey ")
or die(mysql_error());

[Code] .....

I succeeded in printing out the first record where the four tables are joined, but not other instances.my print out is this:

a.column1
a.colum2
b.colum
c.colum
d.colum

But there are about ten instances where the joining conditions are met. How do I print out all the records that have met the condition?

View 2 Replies View Related

Lookup Value Query Joining Two Tables

Jul 20, 2005

Two tables:T1 (c1 int, TestVal numeric(18,2), ResultFactor numeric(18,2))--c1 isthe primary key.T2 (x1 int, FromVal numeric(18,2), ToVal numeric(18,2), Factornumeric(18,2))--x1 is the primary key. T2 contains non-overlappingvalues. So for eg., a few rows in T2 may look like.1, 51, 51.999, 512, 52, 52.999, 52........32, 82, 82.999, 82........T2 is basically a lookup table. There is no relationship between thetwo tables T1 and T2. However, if the TestVal from T1 falls in therange between FromVal and ToVal in T2, then I want to updateResultFactor in T1 with the corresponding value of Factor from the T2table.------Example for illustration only---------------Even though tables cannot be joined using keys, the above problem is avery common one in our everyday life. For example T1 could beemployees PayRaise table, c1=EmployeeID, with "TestVal" representingtest scores (from 1 to 100). T2 representing lookup of the ranges,with "Factor" representing percent raise to be given to the employee.If TestVal is 65 (employee scored 65% in a test), and a row in T2(FromVal=60, ToVal=70, Factor=12), then I would like to update 12 intable T1 from T2 using sql;. Basically T2 (like a global table)applies to all the employees, so EmpID cannot serve as a key in T2.---------------------------------------------------------Could anyone suggest how I would solve MY PROBLEM using sql? I wouldlike to avoid cursors and loops.Reply appreciated.Thanks

View 1 Replies View Related

Mental Block On SQL Query. Joining One To Many With One Of The Many

Sep 25, 2007

Sorry for the akward title, not sure how to say this. I have a Person table and a addresses table. Each person may have many address records as shown below:

Person
-----------
PersonID | AutoNum
fName | varchar
lName | varchar
...etc

Addresses
---------------
addressID | AutoNum
personID | int (FK)
address1 | varchar
city | varchar
state | varchar
isPrimary | bit
...etc


What I'm trying to do is select all from Person and the city and state of each person's primary address. A little voice keeps saying subquery...but I can't figure it out. So far I have the SQL below, but if there is no address or no address where isPrimary = 1, it fails to return the person record. I need the person record regardless of if they have a primary address. Does that make sense?


Doesn't return all Person records:

SELECT Person.*, Address.City, Address.State
FROM Person LEFT OUTER JOIN Address
ON Person.PersonID = Address.PersonID
WHERE (Address.isPrimary= 1)
ORDER BY Person.lName, Person.fName

View 3 Replies View Related

Query Optimization - Joining A View And A Table

Apr 5, 2006

I am having the following situation - there is a view that aggregates and computes some values and a table that I need the details from so I join them filtering on the primary key of the table. The execution plan shows that the view is executed without any filtering so it returns 140 000 rows which are later filtered by the join operation a hash table match. This hash table match takes 47% of the query cost. I tried selecting the same view but directly giving a where clause without the join €“ it gave a completely different execution plan. Using the second method is in at least 4 folds faster and is going only through Index Seeks and nested loops.
So I tried modifying the query with third version. It gave almost the same execution plan as the version 1 with the join operation.
It seams that by giving the where clause directly the execution plan chosen by the query optimizer is completely different €“ it filters the view and the results from it and returns it at the same time, in contrast to the first version where the view is executed and return and later filtered. Is it possible to change the query some how so that it filters the view before been joined to the table.

Any suggestions will be appreciated greatly
Stoil Pankov

"vHCItemLimitUsed" - this is the view
"tHCContractInsured" - this is the table
"ixHCContractInsuredID" - is the primary key of the table

Here is a simple representation of the effect:

Version 1:
select *
from dbo.vHCItemLimitUsed
inner join tHCContractInsured on
vHCItemLimitUsed.ixHCContractInsuredID = tHCContractInsured.ixHCContractInsuredID
where tHCContractInsured.ixHCContractInsuredID in (9012,9013,9014,9015)


Version 2:
select *
from vHCItemLimitUsed
where ixHCContractInsuredID in (9012,9013,9014,9015)

Version 3:
select *
from dbo.vHCItemLimitUsed
where ixHCContractInsuredID in
(select ixHCContractInsuredID
from tHCContractInsured
where ixHCContractInsuredID in (9012,9013,9014,9015))

View 1 Replies View Related

Update Query Joining Tables From Separate Databases

Apr 17, 2008



In database DB1, I have table DB1.dbo.Suppliers1. This table has an ID column of type INT named SUPPL1_ID

In database DB2, I have table DB2.dbo.Suppliers2. This table has an ID column of type INT named SUPPL2_ID
I would like to update DB2.dbo.Suppliers2 based on values from DB1.dbo.Suppliers1 joining on SUPPL1_ID = SUPPL2_ID.

How can I do this in SSIS?

Assumptions:


linked servers are not an option, as I want the SSIS package to be portable and not dependent on server environments.
TIA.

-El Salsero

View 5 Replies View Related

DB Engine :: Possible Ways To Execute A Query Joining Three Tables

May 16, 2015

I am learning the Optimizer from the book "Querying Microsoft SQL Server 2012" for certificate exam 70-461. I really cannot understand how it explains the number of possible ways to execute a query joining three tables. the pseudo-query is:

SELECT A.col5, SUM(C.col6) AS col6sum
FROM TableA AS A
INNER JOIN TableB AS B
ON A.col1 = B.col1
INNER JOIN TableC AS C
ON B.col2 = c.col2
WHERE A.col3 = constant 1
AND B.col4 = constant2
GROUP BY A.col5;

The book says:"Start with the FROM part. Which tables should SQL Server join first, TableA and TableB or TableB and TableC? And in each join, which of the two tables joined should be the left and which one the right table? The number of all possibilities is six, if the two joins are evaluated linearly, one after another."

Q1: How could it be six possibilities? From my understanding, lets say, if the SQL Server has to join A and B first, and then join C, in this case I can think of 4 possibilities, which are:

1. When A Join B, Left: A, Right: B.
    When Join C, Left: result of A join B, Right: C

2. When A Join B, nbsp;  
When Join C, nbsp;When A Join B, nbsp;  
When Join C, nbsp;When A Join B, nbsp;   
When Join C, "line-height:13.5px;">

Q2: The section following the previous question says there are 4 different types of join.."This already gives four options for each join. So far, there are 6 x 4 = 24 different options for only the FROM part of this query."

How can it be 6 x 4? My understanding is 4 is only for 1 join, but in our case, there are 2 joins, so it should be 6 x 4 x 4.

View 4 Replies View Related

SQL Server 2008 :: Query Joining Multiple Tables Getting Duplicates?

May 17, 2013

I'm joining several tables and when I add the last one I get duplicate results. How can I get just one for each?

select a.field, b.field, c.field
from atblname as a inner join btblname as b on a.id = b.parent_id
left outer join ctblname as c on a.id = c.parent_id

There are more than one result when joining tbl a and c, but I'm getting a reult for each of them for all results from joining a and b.

View 9 Replies View Related

Help With Query From A Sql Newbie

Jun 30, 2007

hope someone can help
i have a table a temp table that gets created on a daily basis and can have between 10 -100 rows in it which looks like this

id starttime duration
1 10:00:00 600
2 10:10:00 300
3 11:33:00 15

etc
duration is in seconds
what i want to be able to do is add the start time from a row to the duration from the same row and sutract it from the next rows startime.

Andy

View 7 Replies View Related

Newbie Sql Query Question

Jun 20, 2006

Hi everyone,
I'm working with VWD express 2005 (VB):
I have a simple database with UserId (int), EmployeeName(Varchar), and 7 fields presenting days of the week.(bit/Boolean). It's function is to keep track of which Employees are available at what day(s) of the week.
What I want is for the user to select 1 of the 7 days in a dropdownlist after which a datagridview shows all employees that have that particular day set "true" so...
SELECT * FROM [EmployeeTable] WHERE [value selected index dropdownlist] = true
Question is how do I place the value of the selected day of the dropdownlist in this query? Or is there a better way to write a Select query?
thanks beforehand for your reply !
Sean
 

View 2 Replies View Related

Newbie Query Question.

Dec 5, 2000

I am a newbie to sql queries. IS there a way to get a listing of all the tables and each column in the tables? Thanks
Joe

View 3 Replies View Related

Newbie Query Problem

Mar 5, 2001

Hi, I'm new to SQL and have a problem/query.

I want to return data from 2 tables, tblPerson and tblPersonAddress. A person can have many addresses.

I want to return all the addresses for each person (with id per_id), but I only want the persons name to be returned once.

Currently with the query below I get all addresses, but the names are returned with each address. How do I filter this?

Here's my current query:

SELECT

p.per_id, p.per_last_name,p.per_first_name, pa.add_id, pa.add_text, pa.add_county, pa.add_country

FROM tblPerson p, tblPersonAddress pa

WHERE p.per_id = pa.per_id

GROUP BY p.per_last_name,p.per_first_name,pa.add_id, pa.add_text, pa.add_county, pa.add_country, p.per_id


TIA,
Luke

View 1 Replies View Related

Query Code (newbie)

Nov 27, 2005

Hey everyone,

I know this is a very simple problem however I've literally just begun learning about SQL and this is the first ever code i've created using the language.

The error is:

Msg 102, Level 15, State 1, Line 30
Incorrect syntax near ')'. Located on line containing "create table Trailer_Type"

create table Tralier
(load_types varchar(20),
Serial_no varchar(5),
constraint trailerkey primary key(Serial_no));

create table Tractor
(Reg_no varchar(8),
Descript varchar(20),
constraint tractorkey primary key(Reg_no));

create table Unit
(Unit_no varchar(4),
Total_length int(3),
Max_load int(2),
constraint unitkey primary key(Unit_no));

create table Maintenance
(Reg_no varchar(8),
Date_in date(8),
Date_out date(8),
Descript varchar(20),
Job_no varchar(6),
Mech_name varchar(20),
constraint maintenancekey primary key(Job_no));

create table Load_type
(load_type varchar(20),
constraint typekey primary key(load_type));

create table Trailer_Type
(constraint holds foreign key (serial_number) references
Trailer(serial_no),
Constraint holds foreign key (load_type)
references Load_type(load_type));

I'd be very greatful if someone could help me.

Thanks

David

View 6 Replies View Related

Newbie Needs Help With A Complex Query

Sep 6, 2005

I am new to SQL but I have jumped into it fairly deep. I need to write a query to generate a report that counts systems by the first two characters in the system name and gives a count by the first two characters and a total of all the systems.
The first part I have but I cannot think of how to get an overall total.
Here is the code I am using:
select
substring(dm.[Name],1,2) as 'Location',
count(distinct dm.[Name]) as '# Discovered',
count(distinct w.[Name]) as '# Managed',
count(distinct w.[Name])*100 / count(distinct dm.[Name]) as '% Managed'
from DiscoveredMachines dm, Wrksta w

where datediff(dd,dm.[DiscoveryDate],getdate()) < 90
and dm.[Name] *= w.[Name]
and (dm.[Name] like 'AB%' or dm.[Name]like 'CD%' or dm.[Name] like 'AD%'
or dm.[Name]like 'CB%' or dm.[Name] like 'SX%'
or dm.[Name] like 'EX%')


group by substring(dm.[Name],1,2)

compute sum(count(distinct dm.[Name])),
sum(count(distinct w.[Name]))


The results look like:
Location # Discovered # Managed % Managed
AB 30 27 90
AD 15 15 100
CB 20 19 95
CD 20 20 100
EX 35 30 86
SX 10 9 90

And then a separate result group with

sum sum
130 120

Is there any way I can get the sum on the same result group?
AM I even making sense?

View 3 Replies View Related

Newbie - Filtering A Query

Feb 17, 2006

Hi All

I am writing a query to list all users in 2 countries but exclude users which their name starts with _inactive_5#4$66899, holder_....

I wrote

Select position, subsidiaryName
from position
where subsidiaryname = 'country one' OR subsidiaryname= 'country 2'

I get a result but there are some names which are fake accounts

eg. names start with inactive_#@$%&*ijkgfhg

or with holder_uhgfjgj

how can I do write into the query so that only the proper names without the rows that are fake showing up. In other words i want all results for those 2 countries except ones starting with inactive or with holder......?

thank you:)

View 2 Replies View Related

Newbie Error? Crosstable Query

Mar 30, 2005

I'm struggling with the problem which feels like it shouldn't be taking me this long! Any help would be gratefully received. Simply, there are two tables: Users: userid | username Links: sourceUserId | destUserId sourceUserId and destUserId are both in the users table. I'm trying to write a SP which will output the names of the linked users. eg: Bob | Alice Alice | Geoffrey Peter | Bob Any help gratefully received! Thanks in advance -- Chris

View 2 Replies View Related

Query Formulation Question From SQL Newbie

Oct 20, 2007

I am bulk-loading a large amount of data into a group of related tables. Each table has an identity column as its primary key.

A problem is introduced because I need to break up the bulk-loads into multiple sessions, due to performance and memory constraints. I can get all the foreign key references correct within the scope of a single bulk-load session. However, there are many duplicate rows when you look at the job as a whole.

So, I need to find all the duplicate rows, collapse them down to a single row, and update all the foreign key references in other tables to reference this single row.

I can find all the duplicate rows and generate a table consisting of the primary key ids and the duplicated values, ie:

ID Value
---+-----
1 | Fred
2 | Fred
5 | Ethel
7 | Ethel
9 | Ethel

Now, all I need to do is DELETE all the duplicate rows (in the example above, rows 2, 7 and 9) and generate UPDATE statements for the other tables that reference this one which replace all the duplicate keys with the chosen one (ie. replace all references to foreign key 2 with 1, and all references to foreign key 7 and 9 with 5).

But this is where I'm getting stuck with SQL. I haven't been able to figure out a way to extract just the first row for each group of Values, which contains the primary key I will use to substitute, then generate the correct subquery for the UPDATEs.

I know I can do this sort of thing procedurally, but I'm wondering if there is also an elegant way to do this in SQL. Thanks so much for the help!!

View 1 Replies View Related

SQL Query Problem....newbie Question

Aug 23, 2006

So, I have never worked with SQL in my entire life, but have some basic programming skills. I was given a job to run through two tables, sort some of the information and return the two most recent enteries for the job number. I can sort everything but I am having a hard time just returning the two most recent enteries. I have two tables in which to look from and I think a subquery WHERE with the TOP would work.... yet I have tried everything i can think of and after a good 10 hours of research, im hoping to get some help!

The two most recent enteries that i need returned is "start date" with all the other information...

Here is my code that is from designer (which i have played with to no avail)

SELECT Table1.[Inquiry #], Table1.[TTI #], Table1.[Proj Name], Table1.[Customer Name], Table1.[Date In], Table2.Activity, Table2.[Start Date], Table2.[Stop Date], Table2.[Project Lead]
FROM Table1 INNER JOIN Table2 ON Table1.[Inquiry #] = Table2.[Inquiry #]
GROUP BY Table1.[Inquiry #], Table1.[TTI #], Table1.[Proj Name], Table1.[Customer Name], Table1.[Date In], Table2.Activity, Table2.[Start Date], Table2.[Stop Date], Table2.[Project Lead]
ORDER BY Table1.[Inquiry #], Table2.[Start Date] DESC;

Well, all i can do now is pray someone has the opportunity to help.

Thanks in advance for those who do help.

patrick

View 6 Replies View Related

Newbie Question: Table Polling And Select Query In A Loop

May 2, 2007

Hi,



I am a newbie in SSIS.

Can anybody please help me in the following.



Here is the task that I want to achieve:



1. continously poll a db table every 1 minute,

if the value of a paticular cell in the table has changed since last poll,

then initiate the second task



2. do a select query that picks about 10,000 new rows off another db table,

the 10,000 rows should then be stored in a in-memory dataset.

Every time the poll initiates a new select query, it should insert the new rows to the existing in-memory dataset.

thus if the select runs for 2 times in 2 minutes, the the in-memory dataset would contain a maximum of 20,000 rows.



3. Then I want to apply a set of transformations on the dataset and then finally update some db tables, push some records to the ssas database. (push mode incremental processing)



which sub tasks can be achieved and which cannot.

if not, Is there a workaround?



Please do provide some specific links that accomplish some of these similar tasks.



I have tested some functionality, like

doing a full processing of a ssas database.

reading from a database table and inserting into a flat file.

I tired to use the ExecuteSQLTask, and i also assigned the resultant to an user:variable. the execution completed succesfully but I am not able to see the value of the variable change. also I am not able to use the variable to figure out a change in previous value and thus initiate a sql select. or use the variable to do anything.





Regards

Vijay R



View 6 Replies View Related

Newbie Here With A Newbie Error - Getting Database ... Already Exists.

Feb 24, 2007

Hi there
I sorry if I have placed this query in the wrong place.
I'm getting to grips with ASP.net 2, slowly but surely! 
When i try to access my site which uses a Sql Server 2005 express DB i am receiving the following error:

Server Error in '/jarebu/site1' Application.


Database 'd:hostingmemberasangaApp_DataASPNETDB.mdf' already exists.Could not attach file 'd:hostingmemberjarebusite1App_DataASPNETDB.MDF' as database 'ASPNETDB'.
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.Data.SqlClient.SqlException: Database 'd:hostingmemberasangaApp_DataASPNETDB.mdf' already exists.Could not attach file 'd:hostingmemberjarebusite1App_DataASPNETDB.MDF' as database 'ASPNETDB'.Source Error:



An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:



[SqlException (0x80131904): Database 'd:hostingmemberasangaApp_DataASPNETDB.mdf' already exists.
Could not attach file 'd:hostingmemberjarebusite1App_DataASPNETDB.MDF' as database 'ASPNETDB'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735075
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +359
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
 
 This is the connection string that I am using:
 <connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;Initial Catalog=ASPNETDB;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
 
The database is definitly in the folder that the error message relates to.
What I'm finding confusing is that the connection string seems to be finding "aranga"s database.
Is it something daft?
 
Many thanks.
James 

View 1 Replies View Related

Newbie Query - Replicate To Hot Standby And How To Enable The Hot Standby For Access

Nov 14, 2007



I've been reading a million and one posts on replication

My scenario is that i have a live SQL 2000 server. In a DR invokation, i'e i've lost my live sever, i want to be able to access the same data at the DR (SQL 2000) site and have it accessable to the users. DR server has a different name to the live box.

Replicate

Master
CRMDatabase

Data changes all the time but can have hourly replication of transaction logs for this example. I've currently researched a sp called update logons but this has to be fed each account name to enable them on the new server. There must be a way to activate all CRMDatabase logons with the new server?

Could someone be kind enough to lead me through a step by step guide on the best solution.


Thanks a lot

David

View 3 Replies View Related

Help In Joining

Jan 3, 2008

I want to make some joining in my table but I dont know what kind of joining is appropriate. Here is my tables sample:table1 -> tableid, useridtable2 -> userid, firstname, lastnametable3 -> userid, firstname, lastname Now, I want to to get data from table1 with the data from table2 and table3 where userid of table1 = table2, table3. 

View 2 Replies View Related

Joining From Two Different DB

Apr 17, 2006

May I know how to issue JOIN statement to join two ID from different DB ?
example:
dbA - tableA - a.ID
dbB- tableB - b.ID
Thanks.

View 2 Replies View Related

Joining 2 Tables...

Apr 29, 2007

Hi. I'm new to SQL, and need to join 2 tables... any hints???
 table1:id (int)title(varchar(50))body(text)
 table2:id (int)title(varchar(50))body(text)
somehow need to get the id, which table the record is from, and the title and body... so if the tables had the information:
table1:id          title                       body1           "first title"              "first body"2           "second title"         "second body"3           "third title"             "third body"
table2:id          title                       body1           "first title"              "first body"2           "second title"         "second body"3           "third title"             "third body"
 I would like to get...
id    table         title                     body3      1         "third title"             "third body"3      2         "third title"             "third body"2      1         "second title"         "second body"2      2         "second title"         "second body"1      1         "first title"              "first body"1      2         "first title"              "first body"
 Does anyone know how to get this? I am fairly flexible if i need to change things...
 cheers, eh!

View 1 Replies View Related

Inner Joining Two Tables

Aug 30, 2007

Hello everyone,I'm starting a new project right now and am trying to cut down on the number of stored procedures and tables I'm gonna have to use and I have run into a dead end.Up till now I have been doing the following: Say I had a PRODUCTS table with a DesignId column and ColorId column. I would then create a DESIGN table (Name, Id) and a COLOR table (Name, Id) to INNER JOIN with the two columns in my PRODUCTS table. And the same goes for all my other tables: ORDERS, CUSTOMERS, LINKS etc...... And in the end I would have a lot of tables and stored procedures for these category columns. So I thought, it would be nice to just have a Categories and Subcategories table for all my category columns for the whole website. That way every time I need to define a category column for any table I can simply just add the values to my Categories and Subcategories table instead of having to create a new table for every category column. Everything is fine and dandy except for trying to INNER JOIN these two tables with more than one column. To get values for one column is no problem:<code> SELECT     *,    _SubCategories.SubCategoryNameFROM     _ProductsINNER JOIN     _SubCategoriesON    _Products.DesignId = _SubCategories.SubCategoryIdWHERE    DesignId = COALESCE (@DesignId, DesignId)</code> But how do you INNER JOIN the ColorId column as well. Both DesignId and ColorId values are in my _SubCategories table. In a stored procedure: Is there any way to create a table and columns. Run a loop statement, with one INNER JOIN . Rerun another loop statement with a new INNER JOIN statement? Would that work or does any one else have an idea what would?Thank you guys for the help. It is much appreciated. Alec 

View 11 Replies View Related

Joining Two Tables In .NET??

Jan 14, 2008

Hello all,
I have two datatables "customersReached " and "customersGuessed " and I want to combine them into one table only, the problem is that one table exeeded to the other by two fields, so what can I do???????
Mahmoudona

View 4 Replies View Related







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