|
A solution to one part of the problem can be to define types in sql and then extract that information for code validation. I'd be interested in any tools to do the latter, but this is a nice way to define "constants" or types in sql.
/*Define INENTIFIER as varchar(50*/
IF NOT EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'IDENTIFIER' AND ss.name = N'dbo')
CREATE TYPE dbo.IDENTIFIER from varchar(50) null
/*Use the newly defined system type.*/
ALTER TABLE [dbo].[Customers] ALTER COLUMN [Id] IDENTIFIER /* varchar(50) */
You can use IDENTIFIER for your stored procs and have more control over hard coded lenghts, etc.
|
|
|
|
|
I have never actually needed to use custom types, you would then need to maintain the type in both SQL and your code as SQLDBType would not include your IDENTIFIER type. Not a big deal until someone forgets to sync a new type!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I am having 3 tables... in the third table(Table C) i want to insert the values... which i am having datas( some datas not all) in the first(Table A) and second table(some vales not all) (Table B), by single insert....
how to do this??..
|
|
|
|
|
Try something like
INSERT INTO TableC SELECT TableA.Field, TableB.Field FROM TableA, TableB
|
|
|
|
|
INSERT INTO TABLEC
SELECT tableb.col1,tableb.col1 FROM tablea, tableb
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
if there no restrictions of this script,there must have some repeat results,like if the tableb have 3 rows,the tablec have 3 rows,there will be exists 9 rows,how to solve this?
|
|
|
|
|
My previous post for this thread was only example how to do the insert from select statement. For more specified case then it must have other conditions on select statement and so.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
I have created sql function and stored procedure to calculate work hours of an employee.
timein,timeout,workingHours are the fields.
eg:
TimeIn TimeOut WorkingHours
9:20:00 AM 11:59:59 PM 14:39:59
00:01:00 AM 3:56:40 AM 3:55:40
I calculated workHours using datediff.I have to calculate the sum of WorkingHours also.What can I do for this??Really I m confused..
|
|
|
|
|
Did you try SUM function to get sum of working hours.
example:
select sum(workinghours) from mytable
Or post your query and we will see how concretely to add too sum of working hours.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
Hi,
I have CLR procedure which sends request to server and get the url, I need to open that url into browser. I am trying to do it in the application code by Process.Start("IExplore.exe",url). When I debug the code it runs fine but when it deploy to SQL Server to call from CLR procedure it returns error "Request Failed".
Hope someone can help to solve this.
Thanks
|
|
|
|
|
I have two Tables LIKE Emp(EmpNo,EmpName,DeptNo),Dept(No,Name).
Emp Table looks like:
1 xxx 1,2
2 yyy 2,3
3 zzz 1
Dept Table:
1 aaaa
2 bbbb
3 cccc
My Output will be:
1 xxx aaaa,bbbb
2 yyy bbbb,cccc
3 zzz aaaa
How can I do this in Sqlserver2005
|
|
|
|
|
Your database model is faulty IMAO.
How about:
Emp
EmpID Empname
1 xxx
2 yyy
3 ZZZ
Dept
DeptID Deptname
1 aaaa
2 bbbb
3 cccc
Emp_Dept
EmpID DeptID
1 1
1 2
2 2
2 3
3 1
then you can use
SELECT EmpName,DeptName
FROM Emp e
Join EmpDept ed
ON e.EmpID = ed.EmpID
JOIN Dept d
ON ed.Deptid = d.DeptID
And if you really need to get the deptnames as commaseparated values you can have a look in this thread[^] how to do that.
"When did ignorance become a point of view" - Dilbert
|
|
|
|
|
Ignore this response - it was wrong. Monday morning syndrome.
Do you work in 2 departments? I admit that some corporate structures work in this way, but for the purpose of the OP's question it was unecessary to add a many-to-many relationship between employees and departments. His original structure of 1 department hads many employees, ie a one-to-many relationship (or to put this another way each employee works in just 1 department) would have worked just fine, with just one join in the query.
modified on Monday, August 9, 2010 7:55 AM
|
|
|
|
|
No, if you look at the example data in the OP, it is a many-to-many relationship. Employee xxx works in two departments, aaaa and bbbb. Department aaaa has two employees, xxx and zzz.
|
|
|
|
|
My bad, I interpreted as the nameof the first employee to be "xxx 1" - I now see the deptNo field is a comma-separated list
|
|
|
|
|
J4amieC wrote: Monday morning syndrome.
I know everything about that, except it usually happens to me any day of the week
"When did ignorance become a point of view" - Dilbert
|
|
|
|
|
Ignore this answer. I mis-interpreted your source data.
The above answer, although correct confuses your question somewhat.
All you need is to join employee table to department table using the foreign/primary key between employee and department.
SELECT EmpNo, EmpName, DeptName
FROM Emp
INNER JOIN Dept
ON Emp.DeptNo=Dept.No
modified on Monday, August 9, 2010 7:54 AM
|
|
|
|
|
TRY THIS:
SELECT Emp.EmployeeID, Emp.FirstName,
STUFF((SELECT ',' + DeptName FROM Dept WHERE Dept.DeptID = Emp.DeptID FOR XML PATH('')),1,1,'') AS DeptNames
FROM Employees Emp
|
|
|
|
|
Hi Friends,
I installed Oracle 11g in my XP 64bit OS, now I try to run some scripts in SQLPLUS. How can I check the current default path under SQLPLUS? Namely, where should I store these scripts? From the installation summary, I know where the ORACLE_HOME and ORACLE_BASE are, do I have to set environment variables? Confusing....Hope someone can give me a suggestion.
Thanks
|
|
|
|
|
Your post has so much spaces, it is very hard to read. Fix it so, people may look at it
|
|
|
|
|
The default SQLPlus directory is %ORACLE_HOME%\dbs
The SQLPATH environment variable will allow you to specify the default search path for scripts.
Personally I don't use SQLPlus, I find it a PITA.
"When did ignorance become a point of view" - Dilbert
|
|
|
|
|
I think on Windows it is not necessary to set Oracle's environment variables manually (different from Linux). Scripts can be stored quite anywhere, as you can give the path e.g.
START e:\temp\myscript.sql
But Oracle has often some problems when the path contains spaces (perhaps also with national characters or when the path is "long"), so just avoid that - Oracle is still an 1980ies legacy software.
|
|
|
|
|
thanks so much Guys...^_^
|
|
|
|
|
Dear guru's,
I'm a beginner with "database-programming". My standard task is to read some xml-file in a dataset, then I "hack around" with some relations and display the result in any tabular form (e.g. DataGridView). This is a lot of programming for each different view which I want to have on my data.
But I feel, this is stupid and there are much more effective ways to manage this. My question: How are such tasks (different views on data, without a lot of programming) done?
Any tip for a beginner?
Thanks in advance
modified on Thursday, August 5, 2010 4:22 PM
|
|
|
|
|
Can you elaborate on what you consider different views of the data ?
Do you mean that the same data is filtered, sorted, grouped, but basically the same ?
You can add functionality to the Gridview to do sorting.
A little bit more detail could get you better suggestions.
|
|
|
|