|
hi all,
i have two tables with data.like this
Table 1 Table 2
Name Age Sex Adress Phone no city
Basha 24 m 1 st street 2124 india
Peter 25 m 2nd street 24589 USA out put should be like this:
m1 m2 m3
basha 24 m
1 st street 2124 india
peter 25 m
2 nd street 24589 USA
How can i get the out like this what can i do...
Thanks & Regards,
S.Inayat Basha
modified on Saturday, March 27, 2010 4:11 PM
|
|
|
|
|
I am not sure this can easily be done on the server side.
I may be inclined to do the process on the client:
SELECT Name, Age, Sex, Address, Phone, City
FROM Person p
JOIN Address a
ON a.ID = p.ID
ORDER BY p.Name
Dim count as Integer = 0
Dim arr(( (dt.Rows.Count) * 2) - 1), 2) As String
For Each dr as DataRow In dt
arr( count, 0) = dr("Name").ToString
arr( count, 1) = dr("Age").ToString
arr( count, 2) = dr("Sex").ToString
count += 1
arr( count, 0) = dr("Address").ToString
arr( count, 1) = dr("Phone").ToString
arr( count, 2) = dr("City").ToString
count += 1
Next
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Why, the only reason I can think of for this is to service a presentation requirement, that is a report, output or a form requirement. The relevant word is PRESENTATION, do this type of formatting at the correct place, not in the database, as has been suggested.
This is not a suggestion it is a general rule, a database is for the data, not pissing about with formatting and layout.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm sending data to a closed, vendor application using views. We have one field (role) that represents the role the user plays. The vendor application exposes three of these roles but only as booleans. This is beyond my SQL skill level....how to I take this one field and return three boolean fields out of it?
Thanks,
Michael
|
|
|
|
|
create view view_name as <br />
select field_name as f1, field_name as f2, field_name as f3 from table_name
this will select a column a 3 duplicated columns
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
|
|
|
|
|
As Dmitry suggested, select the column 3 times. You can also incorporate a case statement to send a 1 or 0 as the value.
SELECT
CASE WHEN FieldName = 1 THEN 1 ELSE 0 END F1,
CASE WHEN FieldName = 2 THEN 1 ELSE 0 END F2,
CASE WHEN FieldName = 3 THEN 1 ELSE 0 END F3
FROM TableName
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Looks like your answer gives me the answer I need.
CASE WHEN Role = 1 Then 1 else 0 end IsAdministrator,
CASE WHEN Role = 2 Then 1 else 0 end IsDecisionMaker,
etc.
Thanks,
Michael
|
|
|
|
|
Dimitry --
I now have to add one additional field but this one is harder. Each contact has an AccessGranted table tied to them with the locations they can access. I need to reduce that table down to a boolean CanAccess. How do I do something like that when I don't really have a customer key to work with. This is what my view looks like right now:
SELECT TOP (100) PERCENT dbo.CustomerMaster.BSACustomerKey, dbo.ContactMaster.ContactName, dbo.ContactMaster.BusinessPhone, dbo.ContactMaster.MobilePhone,
dbo.ContactMaster.Email, dbo.ContactMaster.FirstName, dbo.ContactMaster.LastName, dbo.ContactMaster.EmergencyMaintenance,
dbo.ContactMaster.NormalMaintenance, dbo.ContactMaster.NetworkAbuse, dbo.ContactMaster.IssuedSwipeCard, dbo.ContactMaster.CardNumber,
dbo.AddressList.CustomerAddressLine1, dbo.AddressList.CustomerAddressLine2, dbo.AddressList.CustomerAddressLine3, dbo.AddressList.CustomerPostBox,
dbo.CityEnumerator.City, dbo.StateEnumerator.State, dbo.AddressList.CustomerCounty, dbo.AddressList.CustomerCountry, dbo.AddressList.CustomerZipcode,
dbo.ContactMaster.BmcCustKey, CASE WHEN dbo.ContactMaster.Role = 1 THEN 1 ELSE 0 END AS IsAdministrator,
CASE WHEN dbo.ContactMaster.Role = 6 THEN 1 ELSE 0 END AS IsDecisionMaker,
CASE WHEN dbo.ContactMaster.Role = 5 THEN 1 ELSE 0 END AS IsAccountingAP
FROM dbo.ContactMaster INNER JOIN
dbo.CustomerMaster ON dbo.ContactMaster.CompanyID = dbo.CustomerMaster.CustomerIdentity LEFT OUTER JOIN
dbo.AddressList ON dbo.ContactMaster.ContactAddress = dbo.AddressList.AddressIdentity LEFT OUTER JOIN
dbo.CityEnumerator ON dbo.AddressList.CustomerCity = dbo.CityEnumerator.CityIdentity LEFT OUTER JOIN
dbo.StateEnumerator ON dbo.AddressList.CustomerStateorProvince = dbo.StateEnumerator.StateIdentity
WHERE (dbo.CustomerMaster.CustomerStatus = 1) AND (dbo.ContactMaster.Status = 1)
ORDER BY dbo.CustomerMaster.BSACustomerKey
|
|
|
|
|
I'm on a WORKGROUP LAN at home, and I want to connect to an instance of SQL Server 2005 Express on one of the other boxes on the network. I have already enabled remote connections on that instance of SQL Server and restarted the service.
When I try to connect, it tells me this:
TITLE: Connect to Server<br />
------------------------------<br />
Cannot connect to HTPC.<br />
------------------------------<br />
ADDITIONAL INFORMATION:<br />
<br />
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2)<br />
<br />
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
modified on Saturday, March 27, 2010 11:52 AM
|
|
|
|
|
Have you also enabled Named Pipes through the Configuration Manager?
|
|
|
|
|
Yeah.
Could it be a user account problem?
When I try to connect (using Windows Auth), it uses my local box's user account.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Have you got Mixed Authentication set in the Sql Server Express instance? If so, can you connect using non-windows authentication?
I noticed that the message said that it can't find instance HTPC; Is that the name of the instance or is it HTPC\SQLEXPRESS?
|
|
|
|
|
i.j.russell wrote: Have you got Mixed Authentication set in the Sql Server Express instance? If so, can you connect using non-windows authentication?
No, but do I want to use non-windows authentication?
i.j.russell wrote: I noticed that the message said that it can't find instance HTPC; Is that the name of the instance or is it HTPC\SQLEXPRESS?
HTPC is the machine name. The server is HTPC\SQLEXPRESS.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
The reason for asking about mixed mode authentication is that if you can connect using a connectionstring like this;
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;
but not like this;
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
then you do have a permissions issue. However, most connection problems are due to incorrectly naming the server or database. The more things we can discount, the easier it will be to fix.
|
|
|
|
|
This is almost a non-issue, as I have halfway decided to use SqlLite instead. Thanks anyway.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Could someone help me with this one perhaps?
Let's say I have a simple SQL query like:
SELECT EmployeeID, EmployeeName, YearStarted FROM Employees
I'd like to return a fourth column in the result set of which the value is conditional upon the value of another column. For instance, if the value of YearStarted is older than 2007, return 'veteran' otherwise return 'spring chicken'.
I'm thining something like:
SELECT EmployeeID, EmployeeName, YearStarted, IF(YearStarted<2007,'Veteran','Spring Chicken') FROM Employees
but obviously such an IF statement doesn't exist in SQL. Is there another way to do it?
|
|
|
|
|
select
EmployeeID,
EmployeeName,
YearStarted,
case
when YearStarted < 2007 then 'Veteran'
else 'Spring Chicken'
end NewColumn
from
Employees
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
|
|
Wouldn't only string functions work? Just guessing.
|
|
|
|
|
Hi!
I was wondering what edition of SQL server i can install in win 7 ultimate!
Thanx.
|
|
|
|
|
I use SQL Server 2008, if that helps.
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
yeah i forgot to say sql 2008!
but what i meant was which edition? standard? enterprise? ....?
|
|
|
|
|
The OS has very little relevance of the edition you should use, it depends on your database requirements, This may help http://www.microsoft.com/sqlserver/2008/en/us/editions.aspx[^]
If you are asking about a development environment then use either developer or express versions.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
For many years I have been using vb6 with Access Database as back end. In many cases while returning record sets Access is omitting the very first record and it returns the rest of the records. I am really baffled. Please help.
Hi all of you, I have corrected my mistake and got the answer for this question.
Here is how I got it solved. The records were stored with time field. When querying up I did not mention the begining of the starting day (like 00:01 - which implies the start time of the day) and the end of the day in the finishing date. (Thought up this solution very late.) And so I was getting a few records eliminated from the query result set.
Thanks for all of you who tried to help and you can consider my question closed.
Hope this helps somebody.
-- modified 1-Apr-16 12:47pm.
|
|
|
|
|