Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
akamole
Starting Member
17 Posts |
Posted - 2014-01-10 : 09:36:47
|
HiI need to combine data from two tables located in the same database.The column GID in Table 1 and RealEstateID in Table 2 has a common idI want to specify a date interval (AcquistitionDate in Table 2) eg 20131001 to 20131030 and get Name from table 1, and combine these to a result table. Something like this (?):[url]http://stackoverflow.com/questions/16364187/combining-2-sql-queries-and-getting-result-set-in-one[/url] |
|
singularity
Posting Yak Master
153 Posts |
Posted - 2014-01-10 : 09:38:55
|
[code]select a.Name, b.AcquisitionDatefrom table1 ajoin table2 b on a.GID = b.RealEstateID[/code] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-10 : 09:45:37
|
quote: Originally posted by singularity
DECLARE @STart datetime,@End datetimeSELECT @STart='20131001'.@End='20131030'select a.Name, b.AcquisitionDatefrom table1 ajoin table2 b on a.GID = b.RealEstateIDWHERE b.AcquisitionDate BETWEEN @Start AND @End
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
akamole
Starting Member
17 Posts |
Posted - 2014-01-10 : 10:06:53
|
Thank you, i changed from datetime to nvarchar(8) in DECLARE statement and it worked perfectly!quote: Originally posted by visakh16
quote: Originally posted by singularity
DECLARE @STart datetime,@End datetimeSELECT @STart='20131001'.@End='20131030'select a.Name, b.AcquisitionDatefrom table1 ajoin table2 b on a.GID = b.RealEstateIDWHERE b.AcquisitionDate BETWEEN @Start AND @End
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-10 : 23:08:29
|
why? what you're passing are datetime values so variable should be of type datetime and not nvarchar------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|