|
Hello EveryBody
I got 2 Table Customer and Order
Customer Table got two column CustomerID, CustomerName
Order Table got Two Column OrderID, ProductID
CustomerTable:
CustomerID CustomerName
101 James
102 Andy
103 Bryan
OrderTable:
OrderID ProductID CustomerID
1001 10001 101
1002 10002 101
1003 10003 101
1004 10004 102
1005 10005 102
1006 10006 103
I want the output as below
CustomerID CustomerName OrderID ProductID
101 James 1001,1002,1003 10001,10002,10003
102 Andy 1004,1004 10004,10005
103 Bryan 1006 10006
Please help me.
Thanks
Sarfarj Ahmed
|
|
|
|
|
SELECT Column1 & ', ' & Column2 & ', ' & Column3 & ', ' & Column4 FROM TableName WHERE Whatever Try something along those lines.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
getting error message
Msg 402, Level 16, State 1, Line 1
The data types nchar and varchar are incompatible in the boolean AND operator.
Sarfarj Ahmed
|
|
|
|
|
Try replacing the & with + .
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
Still Getting Error
Please send me an Example with SQL code
Thanks
Sarfarj Ahmed
|
|
|
|
|
Ahhh, you need to ensure that all types are the same.
So if you have some int datatypes along with varchar or char you need to cast the int to a varchar. CAST(IntColumn as varchar(length))
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
Hello,
I was trying to build an application using sql server 2000 and asp.net which would use real time resources, and; I have been facing an issue in which when two transactions occur at the same time, down to hh:mm:ss; then in that case a deadlock occurs and none of the transactions are completed. They remain pending unless u manually goto enterprise manager and change the seconds by making them +/-1
This issue can be reduced considerably if milliseconds can be used hh:mm:ss:fff. Is there a way to implement this?
Nikhil Joshi
|
|
|
|
|
Deadlocking does not occur because you have a datetime. It occurs because you have two resources which are locking each other.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I’m trying to make a loop that will select a count of all entries that have a "TimeIn" value on the date defined by an input parameter with an hour value between x & y.
So the first pass through the loop would select a count of all rows with a TimeIn between 00:00:00 and 01:00:00 on the selected day ...
The second pass will select a count of all rows with a TimeIn between 01:00:00 and 02:00:00.
finally it will return counts for each hour in the day.
This is my first attempt at loops in SQL so any push in the right direction would be much appreciated.
Thanks.
|
|
|
|
|
There is a better way to do this.
SELECT
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '00:00:00' AND '01:00:00') AS 'Time1',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '01:00:00' AND '02:00:00') AS 'Time2',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '02:00:00' AND '03:00:00') AS 'Time3',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '03:00:00' AND '04:00:00') AS 'Time4',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '04:00:00' AND '05:00:00') AS 'Time5',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '05:00:00' AND '06:00:00') AS 'Time6',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '06:00:00' AND '07:00:00') AS 'Time7',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '07:00:00' AND '08:00:00') AS 'Time8',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '08:00:00' AND '09:00:00') AS 'Time9',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '09:00:00' AND '10:00:00') AS 'Time10',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '10:00:00' AND '11:00:00') AS 'Time11',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '11:00:00' AND '12:00:00') AS 'Time12',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '12:00:00' AND '13:00:00') AS 'Time13',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '13:00:00' AND '14:00:00') AS 'Time14',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '14:00:00' AND '15:00:00') AS 'Time15',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '15:00:00' AND '16:00:00') AS 'Time16',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '16:00:00' AND '17:00:00') AS 'Time17',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '17:00:00' AND '18:00:00') AS 'Time18',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '18:00:00' AND '19:00:00') AS 'Time19',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '19:00:00' AND '20:00:00') AS 'Time20',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '20:00:00' AND '21:00:00') AS 'Time21',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '21:00:00' AND '22:00:00') AS 'Time22',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '22:00:00' AND '23:00:00') AS 'Time23',
(SELECT COUNT(TimeIn) FROM TableName WHERE TimeIn BETWEEN '23:00:00' AND '24:00:00') AS 'Time24'
FROM TableName
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
If you have SQL-Server then
select convert(varchar(13), TimeIn, 120) + ':00', count(*)
from MyTable
where TimeIn between @x and @y
group by convert(varchar(13), TimeIn, 120) + ':00'
order by 1 SQL is best for set operations. You can do loops and cursors but they tend to be slower and are harder to code.
Regards
Andy
|
|
|
|
|
Ohh so that is better than mine? Cool...
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
I sort of figured that it wouldn't work. It would be a shame for something to be easy once.
Does linking the SQL Servers only work if they are on the same machine? If not, could you give some keywords I can do some searching with. There's no reason to be humble about my ignorance now
Thanks for your help.
OT: I see you are from Glasgow. Any ideas for some good day trips for someone visiting? I've been there twice last year for work and will going back at least once this year.
Brad
The secret to creativity is knowing how to hide your sources. - Albert Einstein
|
|
|
|
|
BRShroyer wrote: Does linking the SQL Servers only work if they are on the same machine?
You can link any SQL Servers together.
BRShroyer wrote: could you give some keywords I can do some searching with
Your starter for 10: sp_addlinkedserver[^]
BRShroyer wrote: I see you are from Glasgow. Any ideas for some good day trips for someone visiting?
Loch Lomond, Isle of Arran (aka Scotland in Miniature), Edinburgh (45 mins on the train), Falkirk Wheel.
|
|
|
|
|
Hi guys,
Please help,I am having an issue with data access block connection to the database from my class library project.
using the data access block to connect to database works fine in my website project. but i try creating a separate class library project to connect to the database i now receive an error message.
"The value can not be null or an empty string."
and this is the code:
<br />
Database motomandb = DatabaseFactory.CreateDatabase();<br />
DbCommand motomandbCommand = motomandb.GetSqlStringCommand(query);<br />
<br />
using(DbConnection motomanConnection = motomandb.CreateConnection())<br />
{<br />
DbTransaction motomanTransaction = motomanConnection.BeginTransaction();<br />
try<br />
{<br />
rowsaffected = motomandb.ExecuteNonQuery(motomandbCommand, motomanTransaction);<br />
motomanTransaction.Commit();<br />
}<br />
catch (Exception e)<br />
{<br />
motomanTransaction.Rollback();<br />
}<br />
}<br />
thanks in advance
|
|
|
|
|
any one here for giving me help that i get a problem to store store jpg files in sql or oracle (blob).
please
i am student of ignou .
|
|
|
|
|
Please post the complete error / problem details.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
|
I am making an control which saves xls file in database attached by user. file size will be of 3 MB and there will be 3 such files. Can someone please help me and tell me how can i directly save the file in database rather then saving it in some location on server.
Ram shankar tripathi
Software Engineer
Telstra
Australia
|
|
|
|
|
I have the next problem: in the table with the primary key field "ID" (it is identity with automatic incrementation) when I delete row, the row isn't completely removed - the ID field remain (although it looks like row was removed) - and as a result, next created row has ID wich is equal to ID of previous deleted row + 1. How to delete row from table with autoincrement primary key correctly?
...fear makes people manageable...
|
|
|
|
|
When you have an identity column you do not get deleted id's back. If you delete all rows from the table and want to reset the identity back to a value you need to do this:
DBCC CHECKIDENT('TableName', RESEED, 1)
Hope that helps.
Ben
|
|
|
|
|
|
Noob question:
If I have several (4-5) computers with SQL Server 2005 Express on them, can they all access the same database file located on a remote/network drive? Would they be able to access it at the same time?
Brad
The secret to creativity is knowing how to hide your sources. - Albert Einstein
|
|
|
|
|
No.
SQL Server opens the file exclusively and controls it completely. Only one instance of SQL Server can open a database file. Also, the files must be on the same physical machine as the SQL Server.
However, you can link SQL Servers together so they can share the data. The SQL Server that owns the file will control all access to the data.
|
|
|
|
|
Hey everyone,
I am working on this project, mostly database driven.
this is what it is about:- The user interface is install on three computer in different location while the database is kept on another computer in a seperate location, which means all three computers has to connected to this sql server to enter and retrive data. That means if the server goes down.. neither of these location will be able to continue there work.
What i am thinking about now, is to install sql server on all three machine so that data is stored at each location and at the end of each day all the data from the three location would be uploaded or Synchronized to the main database.
Problem.. how do i get all three database to Synchronize with the main database? Do i have to hard code this to happen or is there a feature that does this in sql 2000...
your help would be highly appreciated...
thanks.
Nab
|
|
|
|