|
How about:
INSERT INTO EMPLOYEE
SELECT
@empId,
@loginId,
@title,
branchNo,
@Fname,
@idNo,
@physicaladdress,
@province,
@city,
@telephone,
@cellNo,
@Email,
@employeetype,
@salary
FROM BRANCH
WHERE someCriteria
In case thats a bit confusing, you can pull the branchNo from another table while still using all your variable for the other columns to be inserted.
|
|
|
|
|
Hi
I have 2 tables, one is with primary key and the other is foreign key. There is one to many relation between the two tables.
i have written query by joining them as below.
But as the 2nd table has more than 1 row, duplicates are coming in the output.
Hence i want to query in such a way that no duplicates should come. Is there any way for this?
Is it possible to write as below....
select table1.col1, (loop through all the rows in table2 and form a srting of the values) as col2 from table1
Thanks in Advance
Regards
Naina
|
|
|
|
|
You can fix by using distinct or grouping.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
No i couldnt do so.....it is not fixed. Still there are duplicates coming out...
|
|
|
|
|
What you are trying to do is called pivoting. If you google for that you wll find loads of examples.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I dont know about pivot in sqlserver 2005. Thanks for giving me clue. I will check for that.
Regards
Naina
|
|
|
|
|
Pleased to help.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I am creating a C# web application to create dynamic forms. The user can define the form, generate its layout. This form would be availble for transaction.
I am having a query in saving the transaction details of the dynamic form. Can we build seperate tables for each form or can we use the same table to store data of all the forms. Which would be the effecient way?
The DB that we are using is Oracle 10g.
Thanks in advance.
|
|
|
|
|
Friends,
I stored my 200 values in an array and that 200 values represent one record.
It is easy to insert 'n' record, that i did N no. of times with MAX of 20 values but this is first time im supposed to insert this large no. of values.
So donno how to do...
HELP!!!
|
|
|
|
|
I'd look at your database design and see if a table with 200 columns is really necessary. If it is, you can create an SP with 200 parameters or generate a massive insert statement (both of which are not good solutions!)
|
|
|
|
|
You could pass the values into the stored proc as xml and work from that.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I prefer a method that will handle generating the query and parameters automatically, that isn't hard-coded to any particular table.
|
|
|
|
|
Hi All,
I am new to reporting services in SQL Server 2005. I have been able to create a report using Microsoft's SQL Server Bussiness Intelligent Development IDE.
The problem is when I access the report from a web browser it asks me for Reposting server's username and password. I want to share these reports across my LAN creating limited users who can just view the reports and do nothing else.
Please suggest how to go about it.
Further more in my IIS when I go and browse the Report$Machinename it sometime does not load properly with all the components it should show. It behave correctly only randomly.
Regards,
Sandeep
|
|
|
|
|
I was looking for an implementation of "UPSERT" that I could execute with one call to ExecuteNonQuery against SQL Server 2000*. Not being familiar with EXISTS and HAVING, but being very familiar with JOIN, I wrote the following:
INSERT INTO MyTable ( Id )
SELECT T1.Id
FROM ( SELECT Id = @Id ) T1
LEFT OUTER JOIN MyTable T2
ON T1.Id = T2.Id
WHERE T2.Id IS NULL
;
UPDATE MyTable
SET Field1 = @Field1
...
WHERE Id = @Id
It works, and, for the particular task, I'm not concerned about scalability**, but I thought I'd post here to get feedback on whether or not there are commonly-used implementations which are held to be superior.
* I try to be database agnostic, so I prefer solutions that don't rely on a particular database system.
** This particular table has only the Id and one other field, and there will be fewer than 1000 records. However, the general case should be considered.
|
|
|
|
|
DB2, Oracle and SQL Server all support the MERGE statement now and it is ANSI Standardm That is pretty agnostic
|
|
|
|
|
I thought MERGE was new in SQL Server 2008? In which case, it won't work with older versions of SQL Server. The OP specifically says he is using SQL Server 2000.
|
|
|
|
|
Right, I use a bunch of different databases, rarely the latest and greatest.
|
|
|
|
|
Is there an SQL Formatter based on Celko's SQL PROGRAMMING STYLE? Someone has probably written something that can follow my rules, but I have not seen it yet.
|
|
|
|
|
--CELKO-- wrote: Celko's SQL PROGRAMMING STYLE
Got a link?
|
|
|
|
|
It is a book; try Amazon.com or whoever you like.
|
|
|
|
|
Hi,
My database is sql server 2005
I have a city table.
Which contains 300 records.
i am inserting those records in temporary table. using the following code
In first window i wrote following code.
Select * Into #TCity FRom Cp_City
select * from #TCity
select * from sys.objects where name = '#TCity'
In second window i wrote following code,
Select * Into #TCity FRom Cp_City
select * from #TCity
select * from sys.objects where name = '#TCity'
My question how can i create a temporary table with a same name in two different windows.
Thanks
|
|
|
|
|
I believe you would need to create 2 different connections to the database. I believe the temp tables are unique to the session ID that is created when a connection is made.
Q: When you say "In first window ...", do you mean window in the Sql Server Management Studio ? If yes, then it might become a bit tricky to make multiple connections to the same server using the same username.
You could start a second instance of SQL server Management Studio and that will work.
Give it a shot.
|
|
|
|
|
Thanks for the reply
One more qquestion, can u plz tell me the meaning of following line
I cannot define a table without using a Transact SQL
|
|
|
|
|
"I cannot define a table without using a Transact SQL"
This statement is a big vague without knowing some background, but I will try to clarify it.
Transact SQL (TSQL) is the language that MS SQl server uses to manipulate both data and the structure of information stored in the server. TSQL is a superset of the ANSI SQL language, meaning it has additional capabilities that are not defined by the ANSI standard.
Therefore, in order to create a table you must use the language that is supported; in this case the language is Transact SQL.
Does that answer your question, or make it more confusing ?
|
|
|
|
|
In Sql Server Management Studio each time you click New Query it opens a new connection, so there is no problem. In SQL 2005/2008 Management Studio (can't remember 2000) it shows you the SPID number in the status bar, next to your login name.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|