October 13, 2008 at 9:12 am
No, the same one which you pasted i'm running.
October 13, 2008 at 9:15 am
I figured out why, its because I’m working on SQL server 2005 but my database is in SQL server 2000. So that’s why its giving the error at XML as it works only in 2005.
October 13, 2008 at 9:42 am
Hi, do you think can we write without the XML?
October 13, 2008 at 10:04 am
You mentioned earlier that you had tried to create a cross tab report, but were unsuccessful.
Can you post that code here?
Also, are you allowed to use dynamic SQL from inside SQL Server? Meaning, can you create the string in SQL?
October 13, 2008 at 10:18 am
I created cross tab in crystal reports, so there was no code for it.
I didn’t understand the second one, but I think we can create string as long there is no dynamic SQL in the code.
October 13, 2008 at 7:27 pm
Shree (10/13/2008)
Hi, do you think can we write without the XML?
Yep... see the following article...
http://www.sqlservercentral.com/articles/Test+Data/61572/
Also, the folks in charge of the database have made a bloody huge error in not allowing the power of Dynamic SQL. They've allowed their fear of injection attacks as supposedly bad performance to overpower one of the most useful tools there is. They really need to reconsider.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 14, 2008 at 7:20 am
Hi, I saw that article and tried but its not working. Its giving me null values.
October 14, 2008 at 7:28 am
Please post the code that you attempted that did not work. Second, please post sample data / table inserts according to the link in my signature. Third, please stop creating new threads on this issue. (We're up to what, 5 now?)
October 14, 2008 at 8:15 am
Sorry, actually I posted in the wrong forum before. I didn’t find the option to delete the topic. Anyway Madhivanan helped me by giving me this article link.
October 14, 2008 at 7:16 pm
Shree (10/14/2008)
That's a WHOLE lot different than your original request... you sure that's what you want? If so, see the following article for some major performance pitfalls to avoid for that method...
http://www.sqlservercentral.com/articles/Test+Data/61572/
--Jeff Moden
Change is inevitable... Change for the better is not.
October 15, 2008 at 3:09 pm
As I couldn’t convert into separate columns, I will try in this way and I will talk to my user about it.
The same article was given my Amar, but it was taking lot of time to run. So I preferred the other way.
Thank you so much for your help.
I hope my User don’t mind if I get them in CSV format.
October 17, 2008 at 7:52 am
Shree,
You can use CASE command to display the rows into colums; for example;
CREATE TABLE [dbo].[fscity](
[state] [nchar](10) NULL,
[city] [nchar](10) NULL
) ON [PRIMARY]
I inserted couple of cities and used this command;
SELECT
CASE WHEN CITY LIKE 'B%' THEN CITY ELSE '' END as 'CITY1',
CASE WHEN CITY LIKE 'L%' THEN CITY ELSE '' END as 'CITY2',
CASE WHEN CITY LIKE 'H%' THEN CITY ELSE '' END as 'CITY3',
CASE WHEN CITY LIKE 'R%' THEN CITY ELSE '' END as 'CITY4',
STATE
FROM dbo.fscity
the result displays as;
City1 Cty2 City3 city4 State
leesburg VA
HERNDON VA
RESTON VA
BOE VA
VA
October 17, 2008 at 7:53 am
Try this
SELECT
CASE WHEN CITY LIKE 'B%' THEN CITY ELSE '' END as 'CITY1',
CASE WHEN CITY LIKE 'L%' THEN CITY ELSE '' END as 'CITY2',
CASE WHEN CITY LIKE 'H%' THEN CITY ELSE '' END as 'CITY3',
CASE WHEN CITY LIKE 'R%' THEN CITY ELSE '' END as 'CITY4',
STATE
FROM dbo.fscity
Viewing 13 posts - 16 through 27 (of 27 total)
You must be logged in to reply to this topic. Login to reply