|
|
|
Hi, i got 2 tables.. 1 called "accounts" and the other called "event_joined"
inside accounts table i have the following field
accounts
admin_num | name | address | mobile
event joined
id | admin_num | eventid
1 | 123455 | 15
2 | 123455 | 18
3 | 123455 | 22
Now, i want to get all details of accounts as well as 1 more additional information which is counting how many event did the person joined.
In the above, u can see that person "123455" had joined 3 events because there are 3 rows of the same admin_num..
final result would be
admin_num | name | address | mobile | number of event joined
12344 | john tan | address bla bla bla | 91234567 | 3
|
|
|
|
|
select accounts.*,
(select count(event_joined.eventid) from event_joined where event_joined.admin_num=accounts.admin_num) as [Number of event joined]
from accounts
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 problem.
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.
|
|
|
|
|
can you send me how to create a database to create an online trading and shopping site
|
|
|
|
|
Without knowing what you wish to trade, it is almost impossible to advise you, with any detail.
It would also take too much time and space. However, if you go to the top of the page and enter shopping cart into the search box and click go!, you will find lots of articles that will get you started.
When you have had a look and tried a few, I'm sure that you will find help for any specific problems that you might have.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Starter kits can be found here[^]. Check out the "BeerHouse" example
I are troll
|
|
|
|
|
Use master;
go
Create Database [Insert name here];
go
"My interest is in the future because I'm going to spend the rest of my life there." - Charles F. Kettering
|
|
|
|
|
Kindly suggest SQL version to be loaded on Novel Network server
I have tried SQL Express edition but it;s not working
|
|
|
|
|
You need to be more specific!
What do you mean it's not working?
It won't install?
It installs, but you cannot connect?
What?
You might find some useful information here[^].
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hi
I have to get data's from sqlserver 2000 Db to my Sql server 2005 Db, how to do this? is there any way other than linked server..
|
|
|
|
|
BCP, SSIS/DTS or use data compare from red-gate.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I installed SQL Server 2005 on my computer. I am using Vista Ultimate. After installation, I can't login to SQL Server.
It gives the error:
Login Failed for User'DOMAINNAME\ACCOUNTNAME'. (Microsoft SQL Server Error: 18456)
I also have SQL Server Express installed on my computer and I can login to that without any problem.
Any ideas?
[]D @ []v[] []D @ []v[]
|
|
|
|
|
Are you sure you're using the correct account to login with?
"My interest is in the future because I'm going to spend the rest of my life there." - Charles F. Kettering
|
|
|
|
|
Yeah , I'm Sure.
[]D @ []v[] []D @ []v[]
|
|
|
|
|
Hi,
Thanks to a massively helpful ROb ive manged to learn a little about conditional statements in Stored Procedures. However i have now created the following SP and it gives an error when compiling.
Incorrect syntax near the keyword 'ELSE'
CREATE PROCEDURE web.createDefaultAddressBook
(
@tmp_custID bigint,
@tmp_Description varchar(500),
@tmp_NoRecipients bigint,
@tmp_Email varhar(100),
@tmp_Forename varchar(100),
@tmp_Surname varchar(100)
)
AS
BEGIN
declare @key bigint
declare @newSignUpID bigint
--determine id of record if exists
SELECT @key = addMaster_Key FROM tbl_AddressBookMaster WHERE addMaster_UserId = @tmp_custID AND addMaster_Title = 'Default'
IF @key IS null
--address book doesnt exist just so create default
INSERT INTO tbl_AddressBookMaster ([addMaster_UserId], [addMaster_Title], [addMaster_Description], [addMAster_NoRecipients])
VALUES (@tmp_custID, 'Default', @tmp_Description, 0)
SELECT @newSignUpID = SCOPE_IDENTITY()
--add addresses to second table
INSERT INTO tbl_AddressBookAddresses ([adds_ABMId], [adds_Email], [adds_RecipientForename], [adds_RecipientSurname])
VALUES (@newSignUpID, @tmp_Email, @tmp_Forename, @tmp_Surname)
ELSE
--default already exists
--add addresses to second table
INSERT INTO tbl_AddressBookAddresses ([adds_ABMId], [adds_Email], [adds_RecipientForename], [adds_RecipientSurname])
VALUES (@key, @tmp_Email, @tmp_Forename, @tmp_Surname)
END
What am i doing wrong?
Is there a more efficient way to do this considering i will be using it in code which will loop through a huge array and pass new records into the SP?
Effective but simple is probably best at this stage though.
Thanks in advance.
|
|
|
|
|
munklefish wrote: SELECT @key = addMaster_Key FROM tbl_AddressBookMaster WHERE addMaster_UserId = @tmp_custID AND addMaster_Title = 'Default' IF @key IS null
I guess column addMaster_Key return integer value and your query should be:
set @key = (select addMaster_Key FROM tbl_AddressBookMaster WHERE addMaster_UserId = @tmp_custID AND addMaster_Title = 'Default')
IF @key is null then
begin
end
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.
|
|
|
|
|
Thats how it was suggested to me by someone else on here. That part of it works.
Is it more efficient to use SET rather than the SELECT method i have used?
Thanks.
|
|
|
|
|
People argue about that a lot. There's really not much in it. I tend to use SET outside of a select statement (so would use it in your example).
set @now = getdate()
But either is fine.
Regards,
Rob Philpott.
|
|
|
|
|
SO i figured out that i need to place the 'BEGIN' & 'END' blocks within the IF statement.
Any suggestions on optimising the procedure?
|
|
|
|
|
Yeah, as posted above if you have more than one statement in your conditional code you need to place them in a begin-end block.
As a general point, the last two inserts you have there are almost identical, the first parameter being the only difference.
I think you could shorten it to this (or similiar):
IF @key IS null
begin
INSERT INTO tbl_AddressBookMaster ([addMaster_UserId], [addMaster_Title], [addMaster_Description], [addMAster_NoRecipients])
VALUES (@tmp_custID, 'Default', @tmp_Description, 0)
SELECT @key = SCOPE_IDENTITY()
end
INSERT INTO tbl_AddressBookAddresses ([adds_ABMId], [adds_Email], [adds_RecipientForename], [adds_RecipientSurname])
VALUES (@key, @tmp_Email, @tmp_Forename, @tmp_Surname)
Make sense?
Regards,
Rob Philpott.
|
|
|
|
|
THANKS ROB!!!!!!!
Its actually quite easy when you know how, isnt it.
|
|
|
|
|
The block of code inside the IF & ELSE statement should be within BEGIN and END block.
Like this:
IF @key IS null
--address book doesnt exist just so create default
BEGIN
INSERT INTO tbl_AddressBookMaster ([addMaster_UserId], [addMaster_Title], [addMaster_Description], [addMAster_NoRecipients])
VALUES (@tmp_custID, 'Default', @tmp_Description, 0)
SELECT @newSignUpID = SCOPE_IDENTITY()
--add addresses to second table
INSERT INTO tbl_AddressBookAddresses ([adds_ABMId], [adds_Email], [adds_RecipientForename], [adds_RecipientSurname])
VALUES (@newSignUpID, @tmp_Email, @tmp_Forename, @tmp_Surname)
END
ELSE
--default already exists
BEGIN
--add addresses to second table
INSERT INTO tbl_AddressBookAddresses ([adds_ABMId], [adds_Email], [adds_RecipientForename], [adds_RecipientSurname])
VALUES (@key, @tmp_Email, @tmp_Forename, @tmp_Surname)
END
Niladri Biswas
|
|
|
|