|
Dear Friends,
This is the table I have:
ID Qty
1 3
2 4
3 7
4 2
5 1
I want to Select Group of rows those Total Qty is equal to 10.
ie.
ID Qty
Group1 3
Group1 7
Group2 3
Group2 4
Group2 2
Group2 1
Group3 7
Group3 2
Group3 1
Please help me.
Thanks
Raghavendra Hegde.
|
|
|
|
|
To solve this problem you have to Stored procedure .
so not have any group in sql can giving this result
Rami Abd Alhalim
|
|
|
|
|
Hi friend,
Here i am send u a query which is help to get the value by group. i used a table called newtable with the field of empid,empnum where empid is varchar n empnum is int. Now i used inerjoint to find the group value for each giving datas of empnum
"select t1.empid from newtable as t1 inner join (select empid from newtable where empnum=2) as t2 on t1.empid=t2.empid"
I this may solution for ur question.
If u got anything pls reply me.........
Senthil S
Software Engineer
|
|
|
|
|
declare @empid as int
select @empId=isnull(max(empId),100)+1 from tbltempemployee
select @empid
Hi this command will generate empid like
101
102 like...,
Suppose to need some alphabet letter before the empid..,
How to do that?,
Suppose before empid i like to generate "L" char value...,
It will be like this one...,
L101
L102 like...,
How to metion the "L" char before the empId in Auto generation
Regards,
Magi
|
|
|
|
|
Hi
This can be solved by fellowing inner joins method. I thing it may work
"select isnull(max(subfld),1)+1 as val from newtable as t1 inner join (select empid,substring(empid,2,datalength(empid)-1) as subfld from newtable) as t2
on t1.empid=t2.empid"
Table:- newtable
Flds:- empid,empnum
data:- (L1,L2,L3)empid,(2,5,8)empnum
i used inner join n created two tables called t1,t2 which is unique by 'empid'. t2 table having flds like empid n subfld while joining i find the substring of the empid n place it in t2's subfld. then i find the max for that ..
Pls go through above and responce me whatever u got....
thnk u
Senthil S
Software Engineer
|
|
|
|
|
you can used Reserved words @@identity
INSERT Table name DEFAULT VALUES
SELECT @@IDENTITY -- used after any action on db(insert ,update,delete)
or
SELECT IDENT_CURRENT('Table Name')-- used without action this the best
|
|
|
|
|
Hi,
I write a function using Transat-Sql(in sqlserver 2005) which returns a integer. My problem i dont know how to catch the result of my function via C#(Visual 2005). I connect to my database, but the object SqlDatareader does not give me the result of my function.
Thank you for your help
|
|
|
|
|
Use ExecuteScalar for this something like...
wrap the function into a stored proc then call the stored proc:
<br />
SqlCommand command = new SqlCommand("MyStoredProcedure", connection);<br />
command.CommandType = CommandType.StoredProcedure;<br />
object objData = command.ExecuteScalar();<br />
return objData;<br />
|
|
|
|
|
cmd=new sqlcommand("storedname",connection)
cmd.CommandType = CommandType.StoredProcedure
p1 = New SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4)
p1.Direction = ParameterDirection.ReturnValue
cmd.Parameters.Add(p1)
cmd.ExecuteNonQuery()
returnvalue= cmProducts.Parameters("@RETURN_VALUE").Value
Rami Abd Alhalim
|
|
|
|
|
Hello,
Would you please be kind to answer my question !
I have developed an ASP.NET Web application using SQL Server Express 2005 in my local PC where I have used VarBinary(MAX) for an image data storage. It is working fine in my computer. Now, I have configured my SQL Server 2005 in my production server using MyLittleAdmin, I found that, I can not set the value MAX for VarBinary, so I am forced to enter the value of varBinary = 8000. Now, When I insert image to this field more than 8KB, I get the following message,
"String or binary data would be truncated."
So, what does it mean, Is it not really possible to store image or file data in VarBinary which is more than 8KB ? if yes, then how can I configure my table for that using MyLittleAdmin ?
Regards
|
|
|
|
|
I don't know about this software you used "MyLittleAdmin" but I know that when I have a stored procedure that takes a parameter varbinary(MAX), I declare the parameter in the code with a length of -1 as follows:
procedure_Insert.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@picture",
System.Data.SqlDbType.VarBinary, -1,
System.Data.ParameterDirection.Input,
false, 0, 0, "picture", System.Data.DataRowVersion.Current, null)
);
To my knowledge the maximum size of varbinary(MAX) is 2GB but I could be wrong on that one.
Hope this helps
Talal
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Hi Talal,
Thanks a lot for your reply. Actually I am new and I have never used Stored_Procedures. In my web application, I have used SQLDataSouruce to insert the image. I have insert statement:
INSERT INTO [Images] ([title], [description], [imagedata], [mimetype]) VALUES (@title, @description, @imagedata, @mimetype)
Now, this works in my computer using SQLExpress. But the problem is, I will have to specify a value for the database column of [imagedata] in my remote hosting server's SQL, but I did not need to specify the value of [imagedata] (varBinary-MAX) in SQLExpress. How can I overcome this size issue while configuring the database column ?
Regards.
|
|
|
|
|
Could it be possible that the remote SQL server is not version 2005? As I recall, SQL 2000 doesn't have the MAX feature.
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Or also, that your MyLittleAdmin software doesn't support the MAX size. If you have SQL 2005 on your production server, MAX is supported.
|
|
|
|
|
hello frnds,
i want a query which display a record in following manner
suppose i give
select * from TestTable where testName like 'V%'
the result shows the all names start from characters "V"
but is there any way to accept a numberonly after "V"
hope u can help...
thankx in advance
-koolprasad2003
If the message is useful for U then please Rate This message...
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
If you are using SQL-Server then:
... where testName like 'V[0-9]%'
If you are not using SQL-Server then:
... where left(testName,1,2) between 'V0' and 'V9'
Regards
Andy
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".
|
|
|
|
|
greetings people,
simply wondering whether there is another of doing this is standard ANSI Transact SQL.
So is here is the query that im running in SQL Server 2005:
Select flavour, isnull([Period 1],0) as [Period 1] , isnull([Period 2], 0) as [Period 2] from (
select sum(crates) as crates, flavour, dbo.getperiod(saledate,'08 Jul 2007','08 Aug 2007') as Period
from ReportSummary where
dbo.getperiod(saledate,'08 Jul 2007','08 Aug 2007') <> 'unknown' and producttypeid=10
group by flavour,dbo.getperiod(saledate,'08 Jul 2007','08 Aug 2007')
) as p
pivot
(
sum(crates) for period in ([Period 1],[Period 2])
) as pvt
and the result set is as follows:
FLAVOUR Period1 Period2
Bitter Lemon 894.41 0.00
Blackcurrant 892.53 0.00
Citrus 481.25 2.00
Coca-Cola 1346.00 0.00
Coke Light 131.75 0.00
Ginger Ale 404.88 0.00
Orange 2667.92 0.00
Soda Water 327.80 0.00
Sprite 1886.49 0.00
Stoney Ginger Beer 559.71 0.00
Tonic Water 250.00 0.00
my problem is that i need to run the same query in a Sybase databse.HOwever, Sybase does not have the pivot operator. Any other of doing the same thing??
Kind regards,
Pete.
|
|
|
|
|
Hi Pete
You should be able to adapt the following technique:
select flavour,
sum(case when period = 1 then crates else 0 end) as Period1_Total,
sum(case when period = 2 then crates else 0 end) as Period2_Total
from ReportSummary
group by flavour
order by flavour The case clause counts just the crates for the stated period.
Regards
Andy
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".
|
|
|
|
|
hello friends..I got this error while conecting to sqlsever 2005 through Visual studio 2005
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 connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
can anyone help me..to resolve it
|
|
|
|
|
|
|
Thank you,
I tried all these suggestions but still connection is not established..Please Help me
|
|
|
|
|
huh...could it be that your server URL is wrong by any remote chance?
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
I write connection string as
string str="server=pcname/SQLEXPRESS; Initial Catalog=databasename;user=username;password=password ";
Is it right. I am using sql server 2005 express edition
|
|
|
|
|
Could you try:
"data source=PCName\ServerName;initial catalog=DBName;User ID=Username; Password=Password;"
and see what happens?
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|