Thursday, March 29, 2012
Alternate rows from different table
I have a requirement in which I have to display a row from one
table & the corresponding row from the another table. e.g. say there
are 2 tables T1 & T2. Suppose there is a record in T1 say R1 & the
corresponding record in T2 as R1' then the display would come as
R1 /* Data from Table 1 */
R1' /* Data from Table 2 */
R2
R2'
& so on.....
This is possible by manipulating the resultset in a program. But I
would like to know if it is possible in the SQL query.
Thanks & Regards,
Praveenpkb wrote:
> Dear All,
> I have a requirement in which I have to display a row from one
> table & the corresponding row from the another table. e.g. say there
> are 2 tables T1 & T2. Suppose there is a record in T1 say R1 & the
> corresponding record in T2 as R1' then the display would come as
> R1 /* Data from Table 1 */
> R1' /* Data from Table 2 */
> R2
> R2'
> & so on.....
> This is possible by manipulating the resultset in a program. But I
> would like to know if it is possible in the SQL query.
> Thanks & Regards,
> Praveen
Looks like a UNION to me. Assuming r is the common column that
determines R1, R2, etc, try:
SELECT r, col1, col2, ...
FROM
(SELECT r, 1 AS tbl, col1, col2, ...
FROM tbl1
UNION ALL
SELECT r, 2 AS tbl, col1, col2, ...
FROM tbl2) AS T
ORDER BY r, tbl ;
If that's not what you wanted then my signature explains how to post
better questions so that you can get better answers. :-)
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||"pkb" <praveen.bhushan@.gmail.com> wrote in message
news:1138803314.265069.114980@.g49g2000cwa.googlegroups.com...
> Dear All,
> I have a requirement in which I have to display a row from one
> table & the corresponding row from the another table. e.g. say there
> are 2 tables T1 & T2. Suppose there is a record in T1 say R1 & the
> corresponding record in T2 as R1' then the display would come as
> R1 /* Data from Table 1 */
> R1' /* Data from Table 2 */
> R2
> R2'
> & so on.....
> This is possible by manipulating the resultset in a program. But I
> would like to know if it is possible in the SQL query.
> Thanks & Regards,
> Praveen
You could:
select 1 AS rank, ... from T1 where ...
union
select 2 AS rank, ... from T2 where ...
Order by (you will have to add the corresponding columns, whatever that is),
rank
Sorry, can't give you anything more detailed without your table structure.|||Hi David, Raymond,
Thanks for your quick replies. The only problem in the above
solution will come when there is a record which is present in
one of the tables. Actually I wanted to make pairs from the two tables.
Well I have got the idea.
Regards,
Praveen
Tuesday, March 27, 2012
Altering table structure with out deleting replication ?
Is there a way 2 update the table structure that is part of an article
without deleting the replication ?
Best Regards
Shahid Saleem
*** Sent via Developersdex http://www.codecomments.com ***
Shahid,
the best you can do is sp_repladdcolumn and sp_repldropcolumn. Combinations
of these can be used to alter existing column definitions (see
http://www.replicationanswers.com/AddColumn.asp). This all changes in SQL
Server 2005.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
Wednesday, March 7, 2012
Alter Database Collation ( If possible )
Can i change my existing database collation with new one ,if it is possible than how i will be done
Thank's for any suggesion
Faheem Lati
NETWORK SOLUTIONHello Faheem,
You can change the default database collation by writing something like
this:
ALTER DATABSE [testing] COLLATE French_CI_AS
But - this will only change the collation for any new tables. Already
created tables will keep their collation, and you have to change them also,
if that's what you're looking for. Look in BOL for the ALTER TABLE syntax to
change the collation of a table.
HTH,
Andrés Taylor
"Faheem" <anonymous@.discussions.microsoft.com> wrote in message
news:EFF8D2E4-951F-470B-B75D-DFCCE4F1C237@.microsoft.com...
> Dear Experts ,
> Can i change my existing database collation with new one ,if it is
possible than how i will be done.
> Thank's for any suggesion .
> Faheem Latif
> NETWORK SOLUTION
Alter Database Collation ( If possible )
Can i change my existing database collation with new one ,if it is possible than how i will be done.
Thank's for any suggesion .
Faheem Latif
NETWORK SOLUTION
Hello Faheem,
You can change the default database collation by writing something like
this:
ALTER DATABSE [testing] COLLATE French_CI_AS
But - this will only change the collation for any new tables. Already
created tables will keep their collation, and you have to change them also,
if that's what you're looking for. Look in BOL for the ALTER TABLE syntax to
change the collation of a table.
HTH,
Andrs Taylor
"Faheem" <anonymous@.discussions.microsoft.com> wrote in message
news:EFF8D2E4-951F-470B-B75D-DFCCE4F1C237@.microsoft.com...
> Dear Experts ,
> Can i change my existing database collation with new one ,if it is
possible than how i will be done.
> Thank's for any suggesion .
> Faheem Latif
> NETWORK SOLUTION
Alter Database Collation ( If possible )
Can i change my existing database collation with new one ,if it is possible
than how i will be done.
Thank's for any suggesion .
Faheem Latif
NETWORK SOLUTIONHello Faheem,
You can change the default database collation by writing something like
this:
ALTER DATABSE [testing] COLLATE French_CI_AS
But - this will only change the collation for any new tables. Already
created tables will keep their collation, and you have to change them also,
if that's what you're looking for. Look in BOL for the ALTER TABLE syntax to
change the collation of a table.
HTH,
Andrs Taylor
"Faheem" <anonymous@.discussions.microsoft.com> wrote in message
news:EFF8D2E4-951F-470B-B75D-DFCCE4F1C237@.microsoft.com...
> Dear Experts ,
> Can i change my existing database collation with new one ,if it is
possible than how i will be done.
> Thank's for any suggesion .
> Faheem Latif
> NETWORK SOLUTION
Sunday, February 12, 2012
All possible combination in a where condition
In the dataset of a report in the Reporting Services 2000, I need to write an SQL statment with a Where condition which makes all possible combination of 10 conditions.
Could that be done by any way except by ORing and ANDing all the conditions?
For example, If I have three conditions, A, B, and C, I need all possible combinations in a WHERE condition as follows
SELECT *
FROM table
WHERE A = @.A
OR B = @.B
OR C = @.C
OR A = @.A and B = @.B
OR A = @.A and C = @.C
OR B = @.B and C = @.C
OR A = @.A and B = @.B and C = @.C
Note: @.A, @.B, @.C are Report parameters
I need to do the same with 10 conditions, I think it's too much to do it that way.
My question is, is there any other way I can do that with the parameters of a Report in Reporting Services.
Any help is greatly appreciated.
Thank you.SELECT * FROM table t1 CROSS JOIN table t2
?|||How you write it your where clause will be true if any of A = @.A, B = @.B or C = @.C evaluates to true.
SELECT *
FROM table
WHERE A = @.A OR B = @.B OR C = @.C
Will be true for all combinations like (A + @.A and B = @.B) because first statement say that if only 1 is ok it will be true.
|||If it is a stored procedure, pass in -1 or '-1' for All values.
IF @.A = -1 SET @.A = null
IF @.B...
IF @.C...
SELECT *
FROM table
WHERE COALESCE(@.A,A) = A
AND COALESCE(@.B,B) = B
AND COALESCE(@.C,C) = C
COALESCE substitutes null values with the value specified as the second parameter. So A will always = A when @.A = null.
Maybe this will help?