|
Assuming you're collecting data from several tables in ONE database.
Use a union query[^] instead, to fill the record set with the required data.
|
|
|
|
|
Thanks Andersson , but i think UNION is not the right solution here, since it envolve a lot of constraints , like number of coloumns of the two SQL stat. should be the same. Other wise i think it save alot of lines of code
0 will always beats the 1.
|
|
|
|
|
The queries that are unioned together needs to have the same number of columns of the same type with the same names in the same order, that's correct.
But that could be easily fixed using alias and dummy columns.
select a,b,c
from tbl1
union
select x as a,y as b,null as c
from tbl2
|
|
|
|
|
Now this does make sense .... nice work around
It worked fine (even the result data is not that much comprehensive) but it do the job, and save some extra lines of code ... great man, thanks alot
0 will always beats the 1.
|
|
|
|
|
i just put the sqlstat in a seperate string and it worked fine
hello all,
when i run this sql stat, in query design, Access 2007 , it works fine and return records.
SELECT fname, lname FROM names WHERE (location = 'there' AND id In (select id FROM name_street WHERE street = 11))
But when i put it in recordset as
set rcset = db.openrecorset("SELECT fname, lname FROM names WHERE (location = 'there' AND id In (select id FROM name_street WHERE street = 11))")
the record set brings back no records ... WHYYY ????
0 will always beats the 1.
modified on Tuesday, February 8, 2011 3:08 AM
|
|
|
|
|
Could be any number of reasons.
Such as
- You are not using the same database
- There are uncommitted records.
- You are not running the code that you think you are
- You are using some process to determine whether records and that process, not the number of records, is wrong.
|
|
|
|
|
I have a colleague, that has a bit of trouble creating a UDF heres there code but it fails:
CREATE FUNCTION GetData(@Param int)
RETURNS TABLE
AS
RETURN
IF @Param = 1
SELECT * FROM Emp
ELSE
SELECT * FROM Offices
END
The function shall return different table based oppon the condition of the @Param value.
Can someone help ???
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|
|
I haven't written a UDF or a while, and I don't like that design, but can you use a UNION?
SELECT * FROM Emp WHERE @Param=1
UNION ALL
SELECT * FROM Pffices WHERE @Param=0
|
|
|
|
|
|
No this isn't possible with either an inline or multi statement TVF (unless the 2 tables are union compatible?)
so the above reply is only workable solution, if tables are union compatible.
|
|
|
|
|
This is not a valid use for a function, a stored proc maybe but not a function. There is no way that emp and offices are going to be union compatible, if they are then why are they in different tables. You need to rethink your design.
Select * from anytable
This is frowned upon, explicitly declare the fields.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Dear ALl,
i have a record set lets say: set rs = db.openrecordset ("SELECT Name, Location FROM tb1")
I need to add a new field "salary" to rs, so i used : rs.fields.append "salary" , adinteger
salary is of integer datatype
This is not working, it is giving me Typemismatch Error and it highlights "salary" , i also googled, all says the same method to append, but still not working .....
AM not sure whats the error, or why , Any one can guide how to append this coloumn to the recordset ??? any work around ???
Note: I want to fill the values of this "salary" field with numbers from calculations.
Regards,
0 will always beats the 1.
modified on Monday, February 7, 2011 5:48 AM
|
|
|
|
|
scorp_scorp wrote: any work around ???
How about adding a dummy-column in the select-statement? Something like below;
set rs = db.openrecordset ("SELECT Name, Location, 0 As [Salary] FROM tb1") You could then overwrite the values in the new column as required
I are Troll
|
|
|
|
|
Greaaaat, thanks alot, this worked excellent but hence i got another problem:
when now i want to fill this feild (after creation), am doing:
With rs
.AddNew
.Fields("salary") = x
.Update
End With
where x is an integer from some where, i have the following error: Field cannot be updated .
i also used :
rs.Edit
rs("salary").Value = x
rs.Update
also same error
Any hint why this error showing up ??? is it the right way to fill in this field ?? i think it is
0 will always beats the 1.
modified on Monday, February 7, 2011 11:36 PM
|
|
|
|
|
scorp_scorp wrote: Any hint why this error showing up ???
I don't know, would have to look it up. My guess is that the recordset-object is readonly.
What are you trying to achieve, and in what language? If you need to update some records in a database, you'd best execute the Sql against the database-server
I are Troll
|
|
|
|
|
Thaks eddy, i found that recordsets are read only by default ... and also are not modifiable if sql depends on two tables of one-to-many relation or invlove sumation of rows ...
Also, if above conditions are not true, then a recordset to be modifiable, i think attribs should be set like:
set st = db.openrecordset("SQL",2,0,3)
or
set st = db.openrecordset("SQL",adOpenDynamic,adUseNone, adLockOptimistic)
0 will always beats the 1.
|
|
|
|
|
hi everyone,
i have sql server db with a table which contains a field for a workplace and the number of people employed in a specific month and year separated by gender.
it kinda looks like :
workplace month year male female
Microsoft feb 2011 5 1
Google feb 2011 6 2
Intel feb 2011 7 3
Microsoft march 2011 8 4
obviously with different actual data.
is there a way to concatenate the year and month columns and pivoting the data so it'll look something like :
workplace date male female date male female
Microsoft feb 2011 5 1 march 2011 8 4
Google feb 2011 6 2
Intel feb 2011 7 3
sorry if that was a bit too much, I'll be happy to explain myself more clearly if needed.
|
|
|
|
|
Select columnA + columnB from someTable
This concatenates the column vakues. Have you tried using this in your pivot query?
|
|
|
|
|
There are some excellent articles [^]around on that subject.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: There are some excellent articles
Shameless plug, excellent. 5 for that.
And it is a very useful article.
|
|
|
|
|
Hey,
Sorry for the late response, I wasn't around a computer.
While article you added really shed some light about the topic, I still have a small problem.
the article showed how to concatenate to columns into one and then pivot the column, what I want to do is to pivot them both.
So if i refer to the article, instead of having a column for "1996-F" and one for "1996-M" I want two columns, one for "M" and one for "F" and "1996" wrapping them.
something like:
1996
M F
6 5
|
|
|
|
|
Now you are trying to put UI/presentation logic into the database operation. Adding the additional row with the year is not a database operation it needs to be done in your application.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Dears,
I have SQL Server table which includes contains follwing columns
File Name Telephone
MemeberName_TelephoneNumber_IDNUmber ,TelephoneNumber
I need to add one or more column named ID Number and get the value from column Filename.what is the query to get the result?
please help me
|
|
|
|
|
Not entirely clear what you are asking but this might set you in the right direction:
declare @Id int
set @Id = 999
select FileName from [table] where IDNumber = @Id
Hoep that helps.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Howdy!
I'm creating an application to keep track of people at an event. The app will run on a Windows 7 laptop, and have no network connectivity (I believe that means it's single tier?). The app is going to be written in C# 2008 Express, with the database in SQL Server 2008 Express.
Here's the security concerns for the app:
About 8 people (door volunteers) will use the app in a night, to register dancers when they arrive.
Every half hour, the volunteer changes.
The volunteers are highly computer challenged (or must be assumed to be so).
I don't want a windows login for each volunteer.
The app will prompt for the volunteer to "log in" to the app, as their shift starts.
I'm considering a single windows user for the whole app. The volunteer app "login" will just be a record of whose at the door at a giving time.
Here's my question:
Is the best way to set up the database security to create the app user in windows, or to use SQL Authentication from within the program? What considerations indicate the best choice?
Thanks,
Jess
|
|
|
|