|
Good Morning All
i have the Following quey,that i want to put their results into a table like this
SELECT DISTINCT(SS.FUNCTION_KEY),P.FUNC_KEY,P.PROPERTY_ID,SS.LIS_KEY,P.LIS_KEY,SS.FLOOR_AREA,P.ACTUAL_EXTENT<br />
Into Final_Area_GEOSS FROM SDE.PROPERTY P INNER JOIN Scheme_Area_GEOSS SS ON<br />
P.LIS_KEY = SS.LIS_KEY AND SS.FUNCTION_KEY = SUBSTRING(P.FUNC_KEY,1,5)+'0'+substring(P.FUNC_KEY,6,3)<br />
WHERE P.FUNC_KEY LIKE 'GEOSS%' <br />
order by ss.lis_key,p.lis_key
when i run this Query i get an Error that says
Msg 2705, Level 16, State 3, Line 1
Column names in each table must be unique. Column name 'LIS_KEY' in table 'Final_Area_GEOSS' is specified more than once.
i understands what it mean, but it does not matter how many lis_key repeat itself, as long as that data gets into the table.
how can i achieve that
thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Your problem is you cannot have duplicate column names in a table - obviously - and in your query you select SS.LIS_KEY twice. You need to alias one or both of them for example:
SELECT DISTINCT(SS.FUNCTION_KEY),P.FUNC_KEY,P.PROPERTY_ID,SS.LIS_KEY as Geoss_LIS_KEY,P.LIS_KEY as Property_Lis_Key,SS.FLOOR_AREA,P.ACTUAL_EXTENT<br />
Into Final_Area_GEOSS FROM SDE.PROPERTY P INNER JOIN Scheme_Area_GEOSS SS ON<br />
P.LIS_KEY = SS.LIS_KEY AND SS.FUNCTION_KEY = SUBSTRING(P.FUNC_KEY,1,5)+'0'+substring(P.FUNC_KEY,6,3)<br />
WHERE P.FUNC_KEY LIKE 'GEOSS%' <br />
order by ss.lis_key,p.lis_key
That will fix your problem.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
You are a Star my man,
thanks it works
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Thats OK. By the way, you should not do it this way as it locks the system tables in the database for the duration of the query. That prevents any other queries using them and could have a big perforamnce hit.
I would do it like this
SELECT DISTINCT(SS.FUNCTION_KEY),P.FUNC_KEY,P.PROPERTY_ID,SS.LIS_KEY as Geoss_LIS_KEY,P.LIS_KEY as Property_Lis_Key,SS.FLOOR_AREA,P.ACTUAL_EXTENT<br />
Into Final_Area_GEOSS FROM SDE.PROPERTY P INNER JOIN Scheme_Area_GEOSS SS ON<br />
P.LIS_KEY = SS.LIS_KEY AND SS.FUNCTION_KEY = SUBSTRING(P.FUNC_KEY,1,5)+'0'+substring(P.FUNC_KEY,6,3)<br />
<big>WHERE 1 = 2 </big>
which creates an empty table (almost) instantly, and then
<big>Insert Into Final_Area_GEOSS </big><br />
SELECT DISTINCT(SS.FUNCTION_KEY),P.FUNC_KEY,P.PROPERTY_ID,SS.LIS_KEY as Geoss_LIS_KEY,P.LIS_KEY as Property_Lis_Key,SS.FLOOR_AREA,P.ACTUAL_EXTENT<br />
FROM SDE.PROPERTY P INNER JOIN Scheme_Area_GEOSS SS ON<br />
P.LIS_KEY = SS.LIS_KEY AND SS.FUNCTION_KEY = SUBSTRING(P.FUNC_KEY,1,5)+'0'+substring(P.FUNC_KEY,6,3)<br />
WHERE P.FUNC_KEY LIKE 'GEOSS%'
to populate it.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Thanks it worked.
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
interesting... could you please let me in on a secret how this works? it is techniques like this i would like to know... TIA!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
While you are creating a table, either with a 'Create Table...' or 'select * into ...' the system objects such as syscolumns are locked. Obviously while they are lcked no-one ele can create a table. This is particularly apparent where you have a 'select * into #table from ...', tempdb is effectively locked for the duration of the select.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Cheers!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
I want to get two columns data from two tables which are not dependent to each other i.e. no key common in both they are not related to each other.
I can't use JOIN because it needs where clause which uses a common field from both tables.
I just want one column from one table and one column from another and display it.
how can do it?
some unions or any other syntax for that?
Thanks in advance,
|
|
|
|
|
If there is no dependency between the two tables why do you want to bring back this way?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I am not sure what you want to do. Do you think a cross join will give the results that you need?
Mehroz
|
|
|
|
|
hello there,
i have a table that have a column, thats values will always unique, that column data will be in numbers, now i wanna know that what variable should i use, bigint or nvarchar ??
this column will be use in checking(i.e. is this ID exist or not?) and that table have already a PK.
currently i'm using bigint and i think that bigint is taking more space than a string, just a think, cant say surely....
so please suggest about it with a good reason
thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen wrote: currently i'm using bigint and i think that bigint is taking more space than a string, just a think, cant say surely....
Perhaps, if your number is low currently. But, if the number gets big, that will reverse. if you're doing indexing on this id ( which seems the only reason to have it ) a number makes far more sense than a string.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
now i wanna know that what variable should i use, bigint or nvarchar ??
It depends on what's the maximum value you expect in the column. I suppose that you'll never run out of numbers in Bigint unless you handle a billion transactions a day.
currently i'm using bigint and i think that bigint is taking more space than a string
Every character in a nvarchar column occupies 2 bytes. So if you're column is nvarchar(10), it'll occupy 20 bytes of storage(Assuming that the data is 10 characters long). On the other hand, Bigint is 8 bytes for all values in the range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. (thats a lot of numbers)
so please suggest about it with a good reason
One good reason is that a fixed length columns is that indexes will work better on them. Use a bigint type and index it for faster performance of your EXISTS query. If the column stores only numbers, use a suitable numeric datatype. The performance will far offset storage.
SG
Cause is effect concealed. Effect is cause revealed.
|
|
|
|
|
the max lenght of id is 15 and it can be handled by bigint(i.e. 999,999,999,999,999) that also small in size, that mean i'm doing right, i will use "unique index" anyway thanks guys
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
hi,
I'm currently using sql server 2000 for my database.
My problem is that this database now hosted on the server gets updated regularly. I mean, we may want to change the structure of some tables and add new fields to them but at the same time we don't want to lose the data entered by users through our website which connects to this database.
I notmally take a copy of the database and update the tables and add stored procedures and then I generate sql scripts for the new tables and new stored procedures but the problem when I try to edit the structure of a table. This will result in losing the data that was inserted in the table. Because using the "generate sql script" will most probably drop the old table and create a new one with the new fields.
so, now how can I update this table and at the same time preserve the data??? I know that the new fields data will be null but that's fine, I can edit them later.
One more thing..when you guys update databases, what exactly do you do if this database is connected to a website? Do you drop the website temporarily in order to update the database? or what?
I mean what if at the exact moment that you dropped you database, some user was adding data? what will happen then??
thanks
|
|
|
|
|
If I need to make changes to a table structure, I generate an 'ALTER TABLE' command. I do NOT allow the system to drop tables.
If multiple changes need to be completed together or bulk rolled back, put them within a transaction.
If possible, ask the users to halt web access during a schedule maintenance period, or, schedule maintenance through the web site. Many large businesses due that on a regular basis.
Hope that helps,
Tim
|
|
|
|
|
Alter table will make the changes without losing the data.
We user Reg-Gate SQL Compare to generate the scripts for deployment.
You MUST always have a development database (take a copy of the production DB to another server)
We normally identify the quietest time for deploying an update and live with the problem of potentially losing some data. This of course depends on your volume and the size of the deployment.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Respected Sir
I have taken backup of my database and format the system now how I restore my database. I am using Sql server 2000.
or
I have backup of database which i taken from another system. now how I restore that database
Signature preview salil_k_singh 11:06 15 Jul '07
|
|
|
|
|
I would copy the backup locally and then, using 'SQL Server Management Studio', use the graphical interfact to restore the database.
Right click on 'Databases', select 'Restore' and fill in the required pieces.
Tim
|
|
|
|
|
sir
what you mention , this option is not in sql server 2000. then how I restore my database
Signature preview salil_k_singh 11:06 15 Jul '07
|
|
|
|
|
hi all
i tried to find the existing sqlservers in the network,
Eammonn Murray's article helped me to find the existing sql servers,
but it didnt deducted the existing databases in the network,
can any body help .
Thanks in adv
kssk
|
|
|
|
|
Eammonn Murray's article helped me to find the existing sql servers,
but it didnt deducted the existing databases in the network,
Databases exist within a SQL Server instance. You ought to enumerate the Servers first, and query the master DB in each server to find the list of databases available in that particular server. Ofcourse, you need valid credentials to log in into each server.
SG
Cause is effect concealed. Effect is cause revealed.
|
|
|
|
|
Hi friends,
In my application (developed in asp.net 1.1), I am going to implement the Cache dependency mechanism. I want to automatically invalidate the Cache object, once any manipulations done on a particular table in SQL Server.
My application and DB is running in different system. I found in one of the site, to create a trigger on the table which in tern calls the sp_makewebtask System stored procedure and write output of the query into a file.
EXEC sp_makewebtask @outputfile = 'c:\testcache.txt'
@query = 'select top 1 Problem_Category_Code from SMD_Problem_Category'
But the 'C:\testcache.txt' is pointing the local system in which SQL is running. I want to write a file which is available in remote system. I shared a folder from the system and made a mapped drive in the SQL system. (as z:\ drive)
I used the statements as :
@outputfile = 'Z:\testcache.txt' also as @outputfile = '\\10.160.1.4\wc\testcache.txt'
But in both the cases I got the error as:
Msg 16821, Level 11, State 1, Procedure sp_makewebtask, Line 131
SQL Web Assistant: Could not open the output file.
But in one site it is mentioned that, we can use the UNC name if we want to write file in remote system. How can I run the SP?
Can anyone please help me to solve this problem?
I need some swift reply on this issue, as it is very urgent for me.
Thankfully,
jm
|
|
|
|
|
This means that SQL Server does not have the required permission to write into the shared folder.
You ought to give write permission to the account under which SQL Server is running to the shared folder. Make sure you give permission under the "Sharing" tab and "Security" tab.
SG
Cause is effect concealed. Effect is cause revealed.
|
|
|
|
|