|
That has to be the craziest thing I've ever seen and it won't even return the correct answer. It does not handle cases where the category is the first or last on a list. There fore it there is only one or two categories it won't return anything. If there are three or more categories it will only return those in the middle.
|
|
|
|
|
take it carefuly
Patel's table:
ProductID CagtegoryID
1 1,2,
2 1,
3 4,
4 2,3,
search condition :
categoryid=1,2
i transform it to :
CagtegoryID
%,1,%
%,2,%
my statement was
"select * from<br />
[your table ] A <br />
where exists (select 1 from @temp B where ','+A.CagtegoryID like B.CagtegoryID )"
the "','+" can handle the leading first Cagtegory.
and the data in Patel's table "1,2,",the last "," can handle the last one
|
|
|
|
|
Okay - I retract my statement that it won't return the correct data.
However it is still a poor solution. The data should have been properly normalised for this query to work efficiently. This solution can't be optimised by the query optimiser and will always run slowly. That might be fine for a handful of rows but it will take a significant amount of time if the tables grow.
|
|
|
|
|
" it will take a significant amount of time if the tables grow"
yeah ,that's the truth.
i just gived a way to resolve Patel's problem.
in general , yours must be the first and best choice.
|
|
|
|
|
hi
i wrote some line code for one of my friend to get servers list, i simply created an object of SQLDMO.SqlServerClass and called ListAvailableServers or ListInstalledInstances (i cann't remember exactly) ;P
it worked in my machine but when i transfered it to other machine it threw an exception that what is the "NameList" (return value of the called method) , i have no idea why it's not worked
anybody had any idea,
...and i'm using C# 2005 & SqlServer 2000
thx
I Wish the Life Had CTRL-Z
|
|
|
|
|
try
1.install the sql server client on the other machine
2.register SQLDMO.DLL to the other machine using regsvr32 command line
SQLDMO.DLL locates ~~Program Files\Microsoft SQL Server\80\Tools\Binn
you'll have to copy some other dll files in the same folder (i cann't remember exactly) to the other machine before you can register it.
|
|
|
|
|
newbie's question:
how to convert an int to varchar using sql script,such as 1 ->'01' ?
thanks
|
|
|
|
|
i think cast & convert are easiest,
declare @x int
set @x = 1000;
declare @y nvarchar(10)
set @y = cast(@x as nvarchar)
print @y
set @y = convert(nvarchar,@x)
print @y
I Wish the Life Had CTRL-Z
|
|
|
|
|
ooh. i m sorry
i mean how can i convert that to varchar with leading zero:
10 -> 10
0~9 -> '00' ~ '09'
and it will be used in a " insert ... select ... from ..." statement.
i have a table that containts a datetime column.
now i want to transform the data in this to another
i have to convert datetime to varchar
such as : '2007-09-29 08:05'(datetime) -> '08:05' (varchar)
my poor statement is
"convert( varchar, datepart( hour , [DateTime] ) ) +':' +convert( varchar, datepart( minute , [DateTime]) ) "
but the result is '8:5' what my boss don't want
help me.
thanks a lot.
|
|
|
|
|
How about convert(varchar(5),getdate(),8)
|
|
|
|
|
Great!
thank you very much!
|
|
|
|
|
Hi
How can i insert music files in my table
Table Fields
------------------------------------
Sid. SongTitle. SongName. Song.
----------------------------------
can any one give me the syntax
Than Q
Keerthi
|
|
|
|
|
As binary data, i.e, BLOB field.
You must have your file as an array of bytes.
You can do it with .NET, if it's the case.
See you
|
|
|
|
|
Hi,
I have table with 5 column I need to group the duplicate recorde and sum the quantity. And this my table column
Product Quantity price description
How can i do that?
Thank you
sms
|
|
|
|
|
webhay wrote: I need to group the duplicate recorde and sum the quantity. And this my table column
Product Quantity price description
How can i do that?
Select Product, SUM(Quantity) Quantity From tblProducts Group By Product
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
Hi everyone.
I want to know from you guys what approach you're using to persist an object into the SQL Server database?
I and some work mates are discussing about the best approach of doing this for our next project, but we don't have much information or experience about the subject, so any information would be welcomed.
Thanks in advance
|
|
|
|
|
pontonet wrote: I want to know from you guys what approach you're using to persist an object into the SQL Server database?
INSERT statements usually do it for me.
I think you need to provide more detail. For example, are you talking about ORM? Just any type of object? Or do you need to turn an existing object model in to a relational model?
|
|
|
|
|
I meant better approaches, for instance, NHibernate, and so on.
Technologies that does it almost automatically for you, without needing to write much SQL code directly.
|
|
|
|
|
pontonet wrote: I meant better approaches, for instance, NHibernate, and so on.
ORM tools then.
pontonet wrote: Technologies that does it almost automatically for you, without needing to write much SQL code directly.
Ah, well... Can't help you if you are looking for ORM tools. I'm a big fan of creating stored procedures and a DAL that is a proxy for the stored procedure. I don't advocate exposing tables directly on the grounds that it is a security risk.
Although, having said that some ORM tools do make better allowances for stored procedures LLBLGen I believe is one.
|
|
|
|
|
Could somebody kindly tell me what the object reference in Microsoft Access is for the Common Dialog box for the Open File Dialog? The code that I have is as follows:
Private Sub cmdOutputFilePath_Click()
'The error message is a compiler error stating 'User-defined type not defined'
Dim dlgLoadOutputFilePath As FileDialog
Set dlgLoadOutputFilePath = Application.FileDialog( _
FileDialogType:=msoFileDialogOpen)
With dlgLoadOutputFilePath
.AllowMultiSelect = False
.Show
End With
If txtInputFilePath.Value = Null Then
txtOutputFilePath = ""
txtInputFilePath.SetFocus
Else
prgProgressBar.Value = 20
txtMessageBoxText.SetFocus
txtMessageBoxText.Text = "<Message>"
End If
End Sub
|
|
|
|
|
I would like to be able to add a field to an existing table in Microsoft Access. It is my understanding that I would need to use a TableDef object. Could you give me some insights? The code I have now is like so:
Option Compare Database
Public dbsHeadcount As Database
Public Cnxn As ADODB.Connection
Public rstHyperionMany As ADODB.Recordset
Function ProcessHeadcountFile()
On Error GoTo ErrorHandler
Dim strConn As String
Dim rstLoadFile As ADODB.Recordset
Dim cmdSQLLoadFile As ADODB.Command
Dim strSQLLoadFile As String
Dim rstHyperionOne As ADODB.Recordset
Dim cmdSQLHyperionOne As ADODB.Command
Dim strSQLHyperionOne As String
Dim cmdSQLHyperionMany As ADODB.Command
Dim strSQLHyperionMany As String
Dim strFileName As String
Dim qdfTemp As QueryDef
Dim qdfNew As QueryDef
Dim strHoldRecString As String
Dim strMessage As String
Set dbsHeadcount = OpenDatabase("J:\<FILEPATH>\Headcount Database.mdb")
Set Cnxn = New ADODB.Connection
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=J:\<FILEPATH>\Headcount Database.mdb;"
Cnxn.Open strConn
Call LoadExcelIntoAccessTable
Set cmdSQLInputFile = New ADODB.Command
Set cmdSQLInputFile.ActiveConnection = Cnxn
Set cmdSQLHyperionMany = New ADODB.Command
Set cmdSQLHyperionMany.ActiveConnection = Cnxn
strSQLHyperionMany = "SELECT [COUNTRY], [TYPE], [BUSINESS UNIT], " & _
"[L/R/G], [REGION], [JOB FUNCTION], [09/12/2007 Reported] " & _
"FROM [tblInputFile]"
cmdSQLHyperionMany.CommandType = adCmdText
cmdSQLHyperionMany.CommandText = strSQLHyperionMany
Set rstHyperionMany = cmdSQLHyperionMany.Execute()
rstHyperionMany.MoveFirst
Call CreateIndexesForLoadedTable
ErrorHandler:
If Err <> 0 Then
MsgBox Err.Source & ":" & Err.Description, , "Error and Error #" & Err.Number
End If
End Function
Sub LoadExcelIntoAccessTable()
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"tblInputFile", "C:/Employees.xls", True
End Sub
Sub CreateIndexesForLoadedTable()
Dim tdfInputFile As TableDef
Set tdfInputFile = dbsHeadcount.CreateTableDef("tblInputFile")
tdfInputFile.Fields.Append tdfInputFile.CreateField("Date", dbDate)
dbsHeadcount.TableDefs.Append tdfInputFile
ERROR: Here is where it is saying that tblInputFile already exists. How do I append the field called "Date" to the existing table called tblInputFile??????????? :confused::confused::confused:
End Sub
|
|
|
|
|
I have a storedProcedure i need to modify so it can sort by one of two columns, i need to allow the program calling the stored procedure to choose which one it wants the data sorted by, currently there are serveral if statments deciding exactly which select statment i will run, i need all of them to have the order by on the end as a variable passed into the stored procedure, is there any way to do this?
my last try:
if @Filter = 'All' and @DateFrom is Null and @MatterRef = ''<br />
BEGIN<br />
select * <br />
from undertakings <br />
order by <br />
case <br />
when @sortBy = 'matterRef' then undertakings.MatterRef<br />
when @sortBy = 'Date' then undertakings.DateTaken<br />
end<br />
END<br />
if @filter = 'Active' and @DateFrom is Null and @MatterRef = ''<br />
BEGIN<br />
select * <br />
from undertakings <br />
where Discharged = 0 <br />
order by <br />
case <br />
when @sortBy = 'matterRef' then undertakings.MatterRef<br />
when @sortBy = 'Date' then undertakings.DateTaken<br />
end<br />
END<br />
if @Filter = 'Discharged' and @DateFrom is Null and @MatterRef = ''<br />
BEGIN<br />
select * <br />
from undertakings <br />
where Discharged = 1 <br />
order by <br />
case <br />
when @sortBy = 'matterRef' then undertakings.MatterRef<br />
when @sortBy = 'Date' then undertakings.DateTaken<br />
end<br />
END
the procedure is a little more complex, with several other condtions but you should be able to get the idea.
Any help or pointers would be appreciated
|
|
|
|
|
when you have more than one filter criteria It's always a good practice to do it in a single dynamic query (T-Sql String). sp_executesql command can be used to execute a string and also it support's substituting any paramerter values that is specified in T-Sql String. I have gone through your Query and written a stored procedure. Hope it will help you to modify your's...
Create Procedure sp_undertakingsSelect
@Filter NVarchar(50),
@DateFrom DateTime,
@MatterRef NVarchar(200),
@sortBy NVarchar(50)
AS
Set NoCount ON
Declare @SQLQuery AS NVarchar(4000)
Declare @ParamDefinition AS NVarchar(2000)
Set @SQLQuery = 'Select * From undertakings where (1=1) '
If @Filter = 'Active'
Set @SQLQuery = @SQLQuery + ' And Discharged = 0'
If @Filter = 'Discharged'
Set @SQLQuery = @SQLQuery + ' And Discharged = 1'
If @DateFrom Is Not Null
Set @SQLQuery = @SQLQuery + ' And DateTaken >= @DateFrom'
If @MatterRef <> ''
Set @SQLQuery = @SQLQuery + ' And MatterRef LIKE '''+ '%' + @MatterRef + '%' + ''''
If @sortBy = 'matterRef'
Set @SQLQuery = @SQLQuery + ' Order By MatterRef '
If @sortBy = 'Date'
Set @SQLQuery = @SQLQuery + ' Order By DateTaken'
Set @ParamDefinition = '@Filter NVarchar(50),
@DateFrom DateTime,
@MatterRef NVarchar(200),
@sortBy NVarchar(50)'
Exec sp_Executesql @SQLQuery, @ParamDefinition, @Filter, @DateFrom, @MatterRef, @sortBy
If @@ERROR <> 0 GoTo ErrorHandler
Set NoCount OFF
Return(0)
ErrorHandler:
Return(@@ERROR)
GO
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
Worked a treat, many thanks for taking the time to respond to my question.
|
|
|
|
|
Ed Hill _5_ wrote: many thanks
You're most welcome
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|