|
Sir,
This is my Mini Project I will only use 10 to 15 book's Only. Once i add a book name in One table, it will automatically add as another tables header. Please help me if there is any way?
Thanks
Fathima
|
|
|
|
|
take a look at Pivot. Use that with a dynamic sql to construct your book colums.
In this script the @List would bhe your book titles
<br />
BEGIN<br />
Set @SQL = 'SELECT PortfolioID, Portfolio, ' + @List + char(13) <br />
Set @SQL = @SQL + 'FROM (SELECT PortfolioID, Portfolio, A.Element, PFClass ' + char(13) <br />
Set @SQL = @SQL + 'FROM vwPFAttribute A ' + char(13) <br />
Set @SQL = @SQL + 'INNER JOIN PFTree T ON T.PFClassID = A.PFClassID AND T.TreeID = ' + CONVERT(VARCHAR(20),@TreeID) + char(13) <br />
Set @SQL = @SQL + 'WHERE A.PortfolioID NOT IN (SELECT PortfolioID FROM dbo.fn_TreeExcludedPortfolios(' + CONVERT(VARCHAR(20),@TreeID) + ')))P' + char(13) <br />
<br />
Set @SQL = @SQL + 'Pivot (Max(Element) For PFClass In (' + @List + ')) as Pvt' + char(13) <br />
Set @SQL = @SQL + 'Order By Portfolio'<br />
<br />
Print @SQL<br />
END<br />
<br />
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: look at Pivot.
Seems like alot of questions lately floating around PIVOTs
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Nasty bloody things until you get the hang of them. Once you get the idea that there are inner and outer queries it starts to fall into place. I used to do a lot of horrible cursor and while selects to get the same result until 2005.
I broke down into 3 steps
1 Build your query to the minimum of data you need (inner query)
2 build your column string = @List
3 wrap these in the pivot query
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Sir,
That query returns a below error in Parse. am using sqlserver 2005.
' Must Declare a Scalar variable @SQL'
' Must declare a Scalar Variable @OList'
What can i Do Now?
This is sample Program only, hardly i will use only 10 to 15 books only. because this is my mini project. Please help me
|
|
|
|
|
Astonishing - you actually thought that query would run right, it was there as an example.
rrrriiizz wrote: What can i Do Now?
Read the other replies, do some research in BOL on pivot queries, find out what dynamic SQL is. You will not be spoon fed with code, we are here to help you increase your skills and LEARN, not do your job for you.
I strongly suggest you get a book in SQL Server and start from there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi there!!!,
I have one idea for your question.. since this is ur small project try to do it in this way... this is just an alternative way..
Use your front end to for creation of tables...
As you said this may have hardly 15 to 20 records...
Assume that you are using VB.Net as your front end,, then use a for loop to loop through the values underit use table creation script which would greate dynamicly... based on the values.
Hope this gives you a sight!!!
Cheers,
ZAK
ZAK
|
|
|
|
|
Thank You So Much, this was working good in my Project. Thanks a lotttttttttt....
|
|
|
|
|
You are welcome dude!!!!!
ZAK
|
|
|
|
|
we developed windows application using C#,and we created setup file(Using Installer Class also ) for this ,this setup runnig succes fully in my machine ,but problem it was not runnig in Client Machine ,it is showing error " login Failed User is Not Trusted user " . How Can Connect client Sql Server 2005 .Could u Please help me.
|
|
|
|
|
From the error message, I presume you're using Windows Authentication to connect to SQL Server. You have two options here,
1) Add the client's login as a trusted user in SQL Server. (This will only work if you're in domain and the client is also a user in the same domain)
2) Use SQL Server Authentication. (Use a username and password to connect to SQL Server)
Thanks.
|
|
|
|
|
|
hi,
can any one help me that how i convert already stored date value into varchar Data type into Datetime data type .
i have date in this format dd/MM/yyyy and is stored in varchar Data type how i convert whole dates data into datetime in above format .
i want to store only Date portion .iam using sql server 2000 data base .
Regards
Rameez
|
|
|
|
|
select convert(DateTime,dateColumn) from TableName
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
i have 2 table in sqlserver. i want do this command
insert into dabirestan (amuzeshgah) values (select amuzeshgah from dabirestan1)
i want fill the record of table dabirestan1 to table dabirestan
i want write a query. how is my query cammand. do any body know?
|
|
|
|
|
try
insert into dabirestan (amuzeshgah) select amuzeshgah from dabirestan1
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
What Blue_Boy suggested was 100% right in addition to it please make sure that the Second table you use should have the same Design or Table structure of what you are trying to copy to... otherwise the query would fail...
Cheers,
ZAK
|
|
|
|
|
Very excellent performance.. but i cant connect with database..
database error was displayed..
Microsoft OLEDB provider for ODBC drivers(0x80004005)
|
|
|
|
|
jeena9940220765 wrote: Very excellent performance.. but i cant connect with database..
database error was displayed..
Microsoft OLEDB provider for ODBC drivers(0x80004005)
Are you OK ? Please read this[^]
|
|
|
|
|
|
Hi all
I am working with SQL Server express edition. I want to save the results of my query in a text file.
SELECT UserName,JoinDate,PostCount FROM Posts
i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file.
Thanks
|
|
|
|
|
Do some research on CLR Stored procedure.
Parwej Ahamad
R & D: REST services with WCF
|
|
|
|
|
If you're using SSMS to connect to your SQL Server express instance, hit Ctrl + Shift + F and execute your SP.
|
|
|
|
|
Hi i have searched a lot and found that BCP can be used for this purpose.
Now i have written a simple query
Declare @str nvarchar(4000)
set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -T'
Print(@str)
Execute master..xp_cmdshell @str
But i get the Output
SQLState = 08001, NativeError = 126
Error = [Microsoft][SQL Native Client]VIA Provider: The specified module could not be found.
NULL
SQLState = HYT00, NativeError = 0
Error = [Microsoft][SQL Native Client]Login timeout expired
SQLState = 08001, NativeError = 126
Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti
ons.
NULL
I have checked remote connections are enabled......
Looking forward for your reply.
Thanks
|
|
|
|
|
Your BCP command must have the -S "Server Name" included, or else it'll search for the default instance.
set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -S InstanceName -T'
|
|
|
|