.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

generate AccNo in SQL(select min AccNo from table where AccNo>300000000

Posted By:      Posted Date: September 18, 2010    Points: 0   Category :Sql Server
hi all..., i create a registration form and it'll generate AccounNo for user after they click "SAVE" button. my database AccountNo start from 300000000 it's generate ID after >300000000 if i register a person it will register to 300000001 let's say i have AccountNo- 300000001 300000002 300000004 300000005 i dun have "300000003" i want to get that Account No to my registration... when i click "SAVE" it's have to search the minimum Account No from database and add user... how to do this..can anyone modify this code to read min AccountNo from database.. here's the code that i have using : try { connection.Open(); #region Generating a newAccNo SqlCommand newAccNoCommand = connection.CreateCommand(); newAccNoCommand.CommandText = "SELECT TOP 1 AccNo FROM Debtor ORDER BY AccNo DESC"; newAccNoCommand.CommandType = CommandType.Text; int minCurrentAccNo = 0; try { if (!int.TryParse(newAccNoCommand.ExecuteScalar().ToS tring(), out minCurrentAccNo)) { minCurrentAccNo = defaultAccNo; } } catch { minCurrentAccNo = defaultAccNo; } int newAccNo = minCurrentAccNo + 1; newAccNoCommand.Dispose(); #endregion

View Complete Post

More Related Resource Links

generate create script of table using c# and SQL server 7.0, can anyone help me?


I want to generate create table script using c#.net, I want to connect sql server 7.0 and generate table create script. Its urgent kindly help me urgently.

SELECT statement to return NULL by matching data from another table.

Hi,I am fairly new at SQL and I have been struggling for days now trying to find an answer to my problem and i have come to the point where i have run out of ideas and about to give up. I'm hoping someone can put me in the correct path. The problem I have 3 table Table 1 Department" has the following columns: REF, NAME Table 2  "Department_Collection" has the following columns: REF, DEPARTMENT_REF, MANAGER_REF, STORE_REF, ACTIVE Table 3 Store" has the following columns: REF, NAME, STORE_ID  What i am trying to do is to take all the rows in the Department table and get a matching row (DEPARTMENT.NAME, DEPARTMENT_COLLECTION.REF) from the Department_Collection table, if it does not match any then still display DEPARTMENT.NAME but mark DEPARTMENT_COLLECTION.REF as null. I have tried the following select statement but it seem to remove all null values when supplied with a 'storename' SELECT DEPARTMENT.NAME, DEPARTMENT_COLLECTION.REF FROM DEPARTMENT_COLLECTION right outer join DEPARTMENT on DEPARTMENT_COLLECTION.DEPARTMENT_REF = DEPARTMENT.REF left outer join STORE on DEPARTMENT_COLLECTION.STORE_REF = STORE.REF where STORE.NAME = 'storename' order by DEPARTMENT.NAME   Any help will be greatly appreciated. Thanks

select max record to join another table sybase

select a.pono,(select (user) from user where userid=a.userid having date=max(date)) as user from a inner join b on a.no=b.no  in the result , i have selected the same id and retrieve two records every thing are same except the date how can i select the record out of two record which date is max date as the where Clasuse to select correct user poid    date                name 1        12/08/2010      Mary 1        20/08/2010      Peter   now i would like to select name which id=1 and date is max and then use the name to join another table because name is foreign key  

SMO classes to generate alter table script to add columns

How to generate ALTER TABLE script to add columns using SMO and c#.

can alias in select be used for selecting other column in that table?

Hi All,I want to use an alias name in a select clause to select other column in that table? select   top 1 (   case when CreatedByName <> '' then 'yy'         else 'xx' end) as filName, (filName + 'xx')from Order       But it throws error like " Invalid column name 'fileName'."Could you please help me out?

Tricky SELECT query from a Single Table

Hi I have a 2 rows of data in a table as mentioned below   Table1             ElementID Month Year Planned Cost UnplannedCost PlannedExpense UnPlannedExpense 4 9 2010 NULL 40 NULL 20 4 9 2010 400 NULL 200 NULL  I need a SELECT query to get the output in a single row as ElementID Month Year Planned Cost UnplannedCost PlannedExpense UnPlannedExpense 4 9 2010 400 40 200 20 Could anybody help me in writing a query for this? Thanks

generate dinamic rows with tetxbox in asp:table

) dynamically generated new rows containing two columns, one with a display name and the other a textbox for the user to enter a value. " ye="Hola, en TablaVenta () genero dinamicamente nuevas filas que contienen dos columnas una con un nombre para mostrar y la otra un textbox para que el usuario ingrese un valor." closure_uid_83htk5="176" mce_style="BACKGROUND-COLOR: #ebeff9">Hello, in TablaVenta (<asp:table>) dynamically generated new rows containing two columns, one with a display name and the other a textbox for the user to enter a value.When I want to retrieve those rows from the code, I notice that there are no rows created in the tableList<BLL.Producto> productos = new List<BLL.Producto>(); for (int i = 0; i <= TablaVenta.Rows.Count; i++) { TableRow tr = new TableRow(); tr = (TableRow)TablaVenta.Rows[i]; for (int c = 1; c <= tr.Cells.Count; i++) { BLL.Producto unProd = new BLL.Producto(); unProd.Nombre = TablaVenta.Rows[i].Cells[c].Text;   Error: Specified argument was out of the range of valid values.Parameter name: index Do you know, what i can will do? Thankss

SELECT COUNT(*) FROM [Table] from an Oracle database

Hi friends, I have problem when retrieving a result from SELECT COUNT(*) FROM [Table] from an Oracle database. When I try to put the result (single row) in a variable I get the following error message. [Execute SQL Task] Error: An error occurred while assigning a value to variable "RowsSource": "Unsupported data type on result set binding RowsSource.". Pls help me Mahe

How to select bottom record if there is no id in table.

Hi All, I am trying to select the bottom record but there is no id in table. For Example A              B jo             john so             som mo            mon to              tom go              gone

Delete objects from table using another table to select rows - help needed

I have one table named 'dbo.ac_Products'Within this table there is a column named 'ProductId'There is also another table named 'dbo.ac_CatalogNodes'Within this table there is a column named 'CatalogNodeId'and a column named 'CatalogNodeType'I need to delete all the rows from 'dbo.ac_Products' and 'dbo.ac_CatalogNodes' where 'ProductId' = 'CatalogNodeId' and 'CatalogNodeType' = 1Any help would be greatly appreciated!

select only 3 digits from the database table column ?

hi all i want to select data from database like that i have a column name ID , i want to select only first three digits from that column ? how can i do it ?

Avoiding a SELECT distinct query generated by SSAS when using dimension derived from fact table

Hi, I am using a dimension derived out ot a fact table and the factt able primary key is dimension key. Issue is, there are large number of rows and so many attributes. SSAS issues distinct query and it takes large amount of time. Without the distinct statement, query takes only 3 min for 4 million rows. With the distinct, it takes 20 min. Becuase the fact primary key is the dimension key there is no need of a distinct statement. I know there is a option in the dimension to say "By Table" to avoid this. But unfortuantely, i breach the 4 GB limit for strings. Any suggestions for optimization? Thanks,  Sambath

Create store Procedure for select Table by Passing Table Name In Parametere

I want to create a Procudure to Select all Information in Table Like (select * from TableName) but Condition is I do not want to Mention The Fix Table Name I will send the Table Name In a parameter from My Vb.net Project like This (select * from @Parameter ) and Then The Select Procudure work with on That Table. It will be change depend on my vb.net reqierment I already Created a Procudure But it Does not working. It is in below. alter proc AllSelect (@Table varchar (30)) as DECLARE @sql nvarchar(MAX) SET @sql = ' Select * from '+@Table+' ' If possible Please let me know also Update and Delete proc by same way. with Regards Suman Bangladesh

select 15 words(not character) from table


i want to select only 15 words from table  , plz reply me how can i do this???

select data from table where it contain (.) ???


hi all

i have Price column in my table ( tbl1)

1.2           1.44         1              1.66

how can i select the prices that dont contain (.) ??

and then update it to add (.0) to it ???

this mean i will find (1) then convert it to ( 1.0)

please help me ;)

Its posible to do a select without the table and the column names into a stored procedure?



I need your help. Imagine that I have two tables:

  1. ALUMN wich has three columns: IdAlumn, Name and Address.
  2. SPORT wich has columns: IdSport, Name, Players and Description.

Supose that my tables could be differnced by a number 1 is for ALUMN and 2 is for SPORT.

And the columns of each table too. So 1 is for IdAlumn, 2 is for Name and 3 is for Address. 1 is for IdSport, 2 is for Name 3 is for Players and 4 is for Description.

For example the combination of table 2 and column 3 is SPORT-Players.

Then I want to do an stored procedure that receives two parameters (the table, the column) @tab and&

How can I select Table by pussing parameter table name


How can I Create Select store proc for select Table but I will send the Table Name in Parmeter which table I want Like below.



Proc SelectAll







ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend